Skip to content

Commit a636a28

Browse files
committed
♻️ Move logic from λ to private function
1 parent cde47f2 commit a636a28

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/mindlogger_data_export/processors.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ class TypedResponseStructProcessor(ReportProcessor):
143143
PRIORITY = 40
144144

145145
def _run(self, report: pl.DataFrame) -> pl.DataFrame:
146+
def parse_with_nulls(d) -> dict | None:
147+
"""Parse with None fallback for null values."""
148+
response = d["response"]
149+
if (
150+
not response
151+
or response.strip() in ("", "null", "None")
152+
or "value: null" in response
153+
):
154+
return None
155+
return self.PARSER.parse_typed(d["item_type"], response)
156+
146157
return report.with_columns(
147158
response=pl.struct(
148159
status=pl.col("item_response_status"),
@@ -152,7 +163,7 @@ def _run(self, report: pl.DataFrame) -> pl.DataFrame:
152163
item_type=pl.col("item").struct.field("type"),
153164
response=pl.col("item_response").str.strip_chars(),
154165
).map_elements(
155-
lambda d: self.PARSER.parse_typed(d["item_type"], d["response"]),
166+
parse_with_nulls,
156167
schema.RESPONSE_VALUE_SCHEMA,
157168
),
158169
)

0 commit comments

Comments
 (0)