Skip to content

Commit

Permalink
Account for aliases when processing AT tables
Browse files Browse the repository at this point in the history
  • Loading branch information
olejandro committed Dec 1, 2023
1 parent 9e3e5a3 commit 957fafd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions times_reader/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class Config:
times_xl_maps: List[TimesXlMap]
dd_table_order: Iterable[str]
all_attributes: Set[str]
attr_aliases: Set[str]
# For each tag, this dictionary maps each column alias to the normalized name
column_aliases: Dict[Tag, Dict[str, str]]
veda_attr_defaults: Dict[str, Dict[str, list]]
Expand All @@ -162,7 +163,7 @@ def __init__(
times_info_file
)
self.column_aliases = Config._read_veda_tags_info(veda_tags_file)
self.veda_attr_defaults = Config._read_veda_attr_defaults(
self.veda_attr_defaults, self.attr_aliases = Config._read_veda_attr_defaults(
veda_attr_defaults_file
)

Expand Down Expand Up @@ -284,7 +285,7 @@ def _read_veda_tags_info(veda_tags_file: str) -> Dict[Tag, Dict[str, str]]:
@staticmethod
def _read_veda_attr_defaults(
veda_attr_defaults_file: str,
) -> Dict[str, Dict[str, list]]:
) -> Tuple[Dict[str, Dict[str, list]], Set[str]]:
# Read veda_tags_file
with resources.open_text("times_reader.config", veda_attr_defaults_file) as f:
defaults = json.load(f)
Expand All @@ -296,6 +297,10 @@ def _read_veda_attr_defaults(
"tslvl": {"DAYNITE": [], "ANNUAL": []},
}

attr_aliases = {
attr for attr in defaults if "times-attribute" in defaults[attr]
}

for attr, attr_info in defaults.items():
# Populate aliases by attribute dictionary
if "times-attribute" in attr_info:
Expand All @@ -316,4 +321,4 @@ def _read_veda_attr_defaults(
tslvl = attr_defaults["ts-level"]
veda_attr_defaults["tslvl"][tslvl].append(attr)

return veda_attr_defaults
return veda_attr_defaults, attr_aliases
2 changes: 1 addition & 1 deletion times_reader/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ def is_year(col_name):
other_columns = [
col_name
for col_name in df.columns
if col_name not in config.all_attributes
if col_name not in (config.all_attributes | config.attr_aliases)
]
df = pd.melt(
df,
Expand Down

0 comments on commit 957fafd

Please sign in to comment.