Skip to content

Commit

Permalink
Capitalise units
Browse files Browse the repository at this point in the history
  • Loading branch information
olejandro committed Dec 2, 2023
1 parent de09f37 commit aaa84af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion times_reader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def convert_xl_to_times(
transforms.remove_invalid_values,
transforms.process_time_periods,
transforms.generate_all_regions,
transforms.capitalise_attributes,
transforms.capitalise_some_values,
transforms.apply_fixups,
transforms.generate_commodity_groups,
transforms.fill_in_missing_pcgs,
Expand Down
13 changes: 9 additions & 4 deletions times_reader/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,20 +908,25 @@ def generate_all_regions(
return tables


def capitalise_attributes(
def capitalise_some_values(
config: datatypes.Config,
tables: List[datatypes.EmbeddedXlTable],
) -> List[datatypes.EmbeddedXlTable]:
"""
Ensure that all attributes are uppercase
Ensure that all attributes and units are uppercase
"""

# TODO: This should include other dimensions
# TODO: This should be part of normalisation

colnames = ["attribute", "tact", "tcap", "unit"]

def capitalise_attributes_table(table: datatypes.EmbeddedXlTable):
df = table.dataframe.copy()
if "attribute" in df.columns and len(df) > 0:
df["attribute"] = df["attribute"].str.upper()
seen_cols = [colname for colname in colnames if colname in df.columns]
if len(df) > 0:
for seen_col in seen_cols:
df[seen_col] = df[seen_col].str.upper()
return replace(table, dataframe=df)
else:
return table
Expand Down

0 comments on commit aaa84af

Please sign in to comment.