diff --git a/times_reader/datatypes.py b/times_reader/datatypes.py index b58e9d7..ee3d2f9 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]] veda_attr_defaults: Dict[str, Dict[str, list]] @@ -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 ) @@ -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) @@ -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: @@ -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 diff --git a/times_reader/transforms.py b/times_reader/transforms.py index f4ef4a6..da18147 100644 --- a/times_reader/transforms.py +++ b/times_reader/transforms.py @@ -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,