Skip to content

Commit 9d84a46

Browse files
committed
🥅 Handle single-underscore response columns
1 parent 7c87fe7 commit 9d84a46

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/mindlogger_data_export/outputs.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,14 @@ def _map_response_column_names(cname: str) -> str:
141141
return "_".join([parts[1], parts[0].removeprefix("response")])
142142

143143
@staticmethod
144-
def _fill_item_response(*null_score_columns: str) -> Generator[pl.Expr, None, None]:
144+
def _fill_item_response(
145+
df: pl.DataFrame, *null_score_columns: str
146+
) -> Generator[pl.Expr, None, None]:
145147
for col in null_score_columns:
146-
yield pl.col(f"{col}__response").alias(col)
148+
if f"{col}__response" in df.columns:
149+
yield pl.col(f"{col}__response").alias(col)
150+
elif f"{col}_response" in df.columns:
151+
yield pl.col(f"{col}_response").alias(col)
147152

148153
@staticmethod
149154
def _pivot_singleselect(
@@ -225,7 +230,7 @@ def _pivot_singleselect(
225230
col for col in score_columns.values() if df[col].is_null().all()
226231
}
227232
# Fill null <QUESTION> columns with value of <QUESTION>__response.
228-
return df.with_columns(WideFormat._fill_item_response(*null_score_columns))
233+
return df.with_columns(WideFormat._fill_item_response(df, *null_score_columns))
229234

230235
@staticmethod
231236
def _pivot_text(

0 commit comments

Comments
 (0)