TagMap¶
- class flexparameterize.tags.TagMap(mapping: dict[str, str])¶
Maps a tabular source’s column names onto dotted model aliases.
- Parameters:
mapping – Source column name -> model alias (a dotted
plant.unit.variablestring, seemodel_alias()).- Raises:
FlexConfigError – If two tags map to the same alias — the resulting rename would silently drop one of the columns.
Example
>>> import pandas as pd >>> tagmap = TagMap({"FT_0231.PV": "facility.pump.flow_in"}) >>> tagmap.apply(pd.DataFrame({"FT_0231.PV": [1.0]})).columns.tolist() ['facility.pump.flow_in']
- apply(df: DataFrame) DataFrame¶
Return a copy of
dfwith every mapped column renamed to its alias.Columns the map does not name are kept untouched — extra columns are legal,
check_sufficiency()decides what matters. The input frame is never mutated.- Parameters:
df – The source data frame.
- Returns:
A renamed copy.
- classmethod from_file(path) TagMap¶
Load a tag map from a JSON file (the config format).
- Parameters:
path – Path to a
.jsonfile holding a flat object of{"tag": "plant.unit.variable"}pairs.- Returns:
The loaded
TagMap.- Raises:
FlexConfigError – For a non-
.jsonsuffix, a non-object document, or an entry whose value is not a string (the message names the offending key).
- report_unmapped(df: DataFrame) TagReport¶
Report the columns of
dfthis map does not account for.A column counts as accounted for if it is a mapped tag or is already one of the aliases the map produces (so a report on an already-
apply()-ed frame is empty). Suggestions come fromdifflib.get_close_matches()against the mapped tags.- Parameters:
df – The source data frame.
- Returns:
The
TagReport.