Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for aliases when processing AT tables #144

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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