Skip to content

Commit

Permalink
Merge pull request #38 from sedos-project/fix/none-values-in-fk-column
Browse files Browse the repository at this point in the history
Fix None values in FK column
  • Loading branch information
SabineHaas authored Sep 11, 2024
2 parents 661818f + e56cfe9 commit 95d43f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Here is a template for new release sections
-
```

## [Unreleased]
### Changed
- "None" values in possible FK column are overwritten by FK mapping

## [0.21.0] - 2024-06-25
### Changed
- in case of bandwidth values, first value is used for process
Expand Down
19 changes: 14 additions & 5 deletions data_adapter/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,14 @@ def __unpack_bandwidths(self, df: pd.DataFrame) -> pd.DataFrame:
Currently only supports to return the first argument of bandwidths
Different bandwidth types are not supported yet
Example:
Parameters
----------
df : pd.DataFrame
Data containing bandwidths
Returns:
Returns
-------
pd.Dataframe
Modified Dataframe
"""
Expand Down Expand Up @@ -442,11 +446,16 @@ def _get_foreign_keys(process: str, df: pd.DataFrame) -> dict[str, ForeignKey]:
# Check if Fks are unique (cannot have different FKs per process/subprocess)
fk_candidates = {}
for fk_column in fk_column_candidates:
if len(df[fk_column].unique()) > 1:
column_data_without_none = df[fk_column][~df[fk_column].isnull()]
if len(column_data_without_none.unique()) > 1:
continue # no candidate
fk = df[fk_column].iloc[0]
fk = column_data_without_none.iloc[0]
if "." not in fk:
continue # no candidate
if df[fk_column].isnull().sum() > 0:
logging.warning(
f"None values in column '{fk_column}' of process '{process}' will be overwritten by FK values."
)
fk_candidates[fk_column] = ForeignKey(*fk.split("."))
return fk_candidates

Expand Down

0 comments on commit 95d43f8

Please sign in to comment.