Skip to content

Commit

Permalink
Account for aliases when processing AT tables (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
olejandro authored Dec 2, 2023
1 parent 06cd28f commit 073dd9f
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]]
# For each tag, this dictionary specifies comment row symbols by column name
Expand All @@ -166,7 +167,7 @@ def __init__(
self.column_aliases, self.row_comment_chars = 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 @@ -311,7 +312,7 @@ def to_tag(s: str) -> Tag:
@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 @@ -323,6 +324,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 @@ -343,4 +348,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 @@ -1605,7 +1605,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 073dd9f

Please sign in to comment.