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

fix: excel2properties no longer crashes if optional columns are missing (DEV-3468) #907

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dsp_tools/commands/excel2json/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def excel2properties(

property_df = _rename_deprecated_columnnames(df=property_df, excelfile=excelfile)

_do_property_excel_compliance(df=property_df, excelfile=excelfile)

# Not all columns have to be filled, users may delete some for ease of use, but it would generate an error later
property_df = _add_optional_columns(df=property_df)

_do_property_excel_compliance(df=property_df, excelfile=excelfile)

# transform every row into a property
props = [
_row2prop(
Expand Down Expand Up @@ -166,7 +166,7 @@ def _add_optional_columns(df: pd.DataFrame) -> pd.DataFrame:
in_df_cols = set(df.columns)
if not optional_col_set.issubset(in_df_cols):
additional_col = list(optional_col_set.difference(in_df_cols))
additional_df = pd.DataFrame(columns=additional_col, index=df.index, data=None)
additional_df = pd.DataFrame(columns=additional_col, index=df.index)
Nora-Olivia-Ammann marked this conversation as resolved.
Show resolved Hide resolved
df = pd.concat(objs=[df, additional_df], axis=1)
return df

Expand Down
2 changes: 1 addition & 1 deletion src/dsp_tools/commands/excel2json/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def get_labels(df_row: pd.Series[Any]) -> dict[str, str]:
Returns:
A dictionary with the language tag and the content of the cell
"""
return {lang: df_row[f"label_{lang}"] for lang in languages if df_row[f"label_{lang}"] is not pd.NA}
return {lang: df_row[f"label_{lang}"] for lang in languages if not pd.isna(df_row[f"label_{lang}"])}


def get_comments(df_row: pd.Series[Any]) -> dict[str, str] | None:
Expand Down