Skip to content
Merged
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
20 changes: 12 additions & 8 deletions src/power_grid_model_io/converters/tabular_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,14 +482,18 @@ def _parse_col_def_column_name(
col_data = self._apply_multiplier(table=table, column=col_name, data=col_data)
return pd.DataFrame(col_data)

try: # Maybe it is not a column name, but a float value like 'inf', let's try to convert the string to a float
const_value = float(col_def)
except ValueError:
# pylint: disable=raise-missing-from
columns_str = " and ".join(f"'{col_name}'" for col_name in columns)
raise KeyError(f"Could not find column {columns_str} on table '{table}'")

return self._parse_col_def_const(data=data, table=table, col_def=const_value, table_mask=table_mask)
def _get_float(value: str) -> Optional[float]:
try:
return float(value)
except ValueError:
return None

# Maybe it is not a column name, but a float value like 'inf', let's try to convert the string to a float
if (const_value := _get_float(col_def)) is not None:
return self._parse_col_def_const(data=data, table=table, col_def=const_value, table_mask=table_mask)

columns_str = " and ".join(f"'{col_name}'" for col_name in columns)
raise KeyError(f"Could not find column {columns_str} on table '{table}'")

def _apply_multiplier(self, table: str, column: str, data: pd.Series) -> pd.Series:
if self._multipliers is None:
Expand Down