Skip to content

Commit

Permalink
Optimise imports in utils; address code warnings (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
olejandro authored Nov 29, 2023
1 parent 26c03bf commit 303aa2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion times_reader/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def process_flexible_import_tables(
# Get a list of allowed values for each category.
legal_values = {
"limtype": {"LO", "UP", "FX"},
"timeslice": utils.timeslices(tables),
"timeslice": utils.extract_timeslices(tables),
"commodity-out": set(
utils.merge_columns(tables, datatypes.Tag.fi_comm, "commodity")
),
Expand Down
28 changes: 13 additions & 15 deletions times_reader/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from pandas.core.frame import DataFrame
import pandas as pd
import re
from dataclasses import replace
from math import log10, floor
from typing import Iterable, List
from more_itertools import locate, one
from itertools import groupby

import numpy
import re
import os
from concurrent.futures import ProcessPoolExecutor
from functools import reduce
from math import log10, floor
import pandas as pd
from more_itertools import one
from pandas.core.frame import DataFrame

from . import datatypes


Expand Down Expand Up @@ -61,13 +59,13 @@ def explode(df, data_columns):

names = pd.Series(data_columns * nrows, index=df.index, dtype=str)
# Remove rows with no VALUE
filter = df[value_column].notna()
df = df[filter]
names = names[filter]
index = df[value_column].notna()
df = df[index]
names = names[index]
return df, names


def timeslices(tables: List[datatypes.EmbeddedXlTable]):
def extract_timeslices(tables: List[datatypes.EmbeddedXlTable]):
"""
Given a list of tables with a unique table with a time slice tag, return a list
with all the column names of that table + "ANNUAL".
Expand Down Expand Up @@ -142,7 +140,7 @@ def apply_wildcards(
wildcard_map = {}
all_wildcards = df[wildcard_col].unique()
for wildcard_string in all_wildcards:
if wildcard_string == None:
if wildcard_string is None:
wildcard_map[wildcard_string] = None
else:
wildcard_list = wildcard_string.split(",")
Expand Down Expand Up @@ -174,7 +172,7 @@ def missing_value_inherit(df: DataFrame, colname: str):
"""
last = None
for index, value in df[colname].items():
if value == None:
if value is None:
df.loc[index, colname] = last
else:
last = value
Expand Down

0 comments on commit 303aa2c

Please sign in to comment.