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

Reset region specification if found in fi_* tables of subres #314

Merged
merged 4 commits into from
Feb 4, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

env:
PY_VERSION: "3.11"
CACHE_KEY: 2 # Use this for manual cache key bumps, e.g., when caching code changes
CACHE_KEY: 3 # Use this for manual cache key bumps, e.g., when caching code changes

steps:
- uses: actions/checkout@v4
Expand Down
26 changes: 21 additions & 5 deletions xl2times/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,10 @@ def fill_in_column_defaults(
if row["region"] in model.internal_regions:
vt_regions[row["bookname"]].append(row["region"])

def fill_in_column_defaults_table(table):
df = table.dataframe
default_values = config.column_default_value.get(table.tag, {})
def fill_in_column_defaults_table(table: EmbeddedXlTable):
df, tag, filename = (table.dataframe, table.tag, table.filename)
module_type = DataModule.module_type(filename)
default_values = config.column_default_value.get(Tag(tag), {})

for colname in df.columns:
# Get the default value for the column if it exists
Expand All @@ -859,9 +860,24 @@ def fill_in_column_defaults_table(table):
# Apply default values to cells that are empty
df[colname] = df[colname].fillna(col_default_value)
elif colname == "region":
# Use BookRegions_Map to fill VT_* files, and all regions for other files
matches = re.search(r"VT_([A-Za-z0-9]+)_", Path(table.filename).stem)
isna = df[colname].isna()
# Region dimension is not supported in subres in fi_t and fi_process tables
if (
module_type == "subres"
and tag in {Tag.fi_t, Tag.fi_process, Tag.fi_comm}
and any(~isna)
):
logger.warning(
f"Unsupported dimension. Encountered region specification in file {filename}, "
f"on sheet {table.sheetname}, within range {table.range}. It will be reset."
)
isna = pd.Series(True, index=df.index)
# Use BookRegions_Map to fill VT_* files, and all regions for other files
matches = (
re.search(r"VT_([A-Za-z0-9]+)_", Path(filename).stem)
if module_type == "base"
else None
)
if matches is not None:
book = matches.group(1)
if book in vt_regions:
Expand Down
Loading