Skip to content

Commit

Permalink
fix: retain start_group and end_group even if name field is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Sep 17, 2024
1 parent a34f130 commit 3f8b854
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions osm_fieldwork/update_xlsform.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@


def filter_df_empty_rows(df, column=NAME_COLUMN):
"""Remove rows with None values in the specified column."""
"""Remove rows with None values in the specified column, but retain group rows if they exist."""
if column in df.columns:
return df.dropna(subset=[column])
# Only retain 'begin group' and 'end group' if 'type' column exists
if "type" in df.columns:
return df[(df[column].notna()) | (df["type"].isin([BEGIN_GROUP, END_GROUP]))]
else:
return df[df[column].notna()]
return df


Expand Down Expand Up @@ -78,7 +82,7 @@ def merge_dataframes(mandatory_df, custom_df, digitisation_df, is_survey_sheet=F
def create_group(name: str) -> dict[str, pd.DataFrame]:
"""Helper function to create a start and end group for XLSForm."""
start_group = pd.DataFrame({"type": [BEGIN_GROUP], "name": [name]})
end_group = pd.DataFrame({"type": [END_GROUP], "name": [name]})
end_group = pd.DataFrame({"type": [END_GROUP], "name": [f"end of {name}"]})
return {"start": start_group, "end": end_group}


Expand Down

0 comments on commit 3f8b854

Please sign in to comment.