From 073dd9fcf8fe3dafa7b9157c3f415d8d55143c2a Mon Sep 17 00:00:00 2001 From: Olexandr Balyk Date: Fri, 1 Dec 2023 22:08:45 -0500 Subject: [PATCH] Account for aliases when processing AT tables (#144) --- times_reader/datatypes.py | 11 ++++++++--- times_reader/transforms.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/times_reader/datatypes.py b/times_reader/datatypes.py index 27449b8..5d23f33 100644 --- a/times_reader/datatypes.py +++ b/times_reader/datatypes.py @@ -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 @@ -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 ) @@ -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) @@ -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: @@ -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 diff --git a/times_reader/transforms.py b/times_reader/transforms.py index eb6c171..669f669 100644 --- a/times_reader/transforms.py +++ b/times_reader/transforms.py @@ -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,