switch Nan values to None#578
Conversation
Walkthrough
ChangesIssue log null normalisation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
digital_land/log.py (1)
168-175: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winUse
pd.isna()here.
v != vonly catches floatNaN, sopd.NAandpd.NaTcan slip through and be stringified in the CSV output as<NA>/NaT.pd.isna(v)handles all Pandas null scalars and is clearer.♻️ Proposed refactor
# Switch Pandas NaN to None to avoid issues with JSON self.rows = [ { - k: (None if isinstance(v, float) and v != v else v) + k: (None if pd.isna(v) else v) for k, v in row.items() } for row in merged_df.to_dict(orient="records") ]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@digital_land/log.py` around lines 168 - 175, Update the row-value normalization in the list comprehension building self.rows to use pandas’ pd.isna(v) for null detection instead of the float-specific v != v check, while preserving non-null values unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@digital_land/log.py`:
- Around line 168-175: Update the row-value normalization in the list
comprehension building self.rows to use pandas’ pd.isna(v) for null detection
instead of the float-specific v != v check, while preserving non-null values
unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 96a22dc6-6537-42c9-8db9-5b06849db6a9
📒 Files selected for processing (1)
digital_land/log.py
What type of PR is this? (check all applicable)
Description
When adding the severity column in
log.py, Pandas represents missing values asNaN. Serialising these to JSON producesNaNtokens, which PostgREST rejects for ajsonbcolumn ("NaN is invalid"), causingadd_datato fail. This converts PandasNaNvalues toNoneso they serialise asnull/blank.Can see in digital_land/check.py, entity is now added to the issue log, this will be added as a NaN value here, (is it worth adding to the issue log here?) and this is NaN causes json write issues.
Related Tickets & Documents
QA Instructions, Screenshots, Recordings
Please replace this line with instructions on how to test your changes, a note
on the devices and browsers this has been tested on, as well as any relevant
images for UI changes.
Added/updated tests?
We encourage you to keep the code coverage percentage at 80% and above. Please refer to the Digital Land Testing Guidance for more information.
have not been included
[optional] Are there any post deployment tasks we need to perform?
[optional] Are there any dependencies on other PRs or Work?
Summary by CodeRabbit
Summary by CodeRabbit
NaN.