fix: serialize NaT in NumPy datetime64 arrays as JSON null by senanurcetin · Pull Request #5831 · plotly/plotly.py · GitHub
Skip to content

fix: serialize NaT in NumPy datetime64 arrays as JSON null - #5831

Draft
senanurcetin wants to merge 8 commits into
plotly:mainfrom
senanurcetin:fix/issue-5829-nat-datetime-arrays
Draft

senanurcetin wants to merge 8 commits into
plotly:mainfrom
senanurcetin:fix/issue-5829-nat-datetime-arrays

Conversation

@senanurcetin

Copy link
Copy Markdown
Contributor

Summary

Closes #5829.

Fix NumPy datetime64 arrays containing NaT being serialized incorrectly instead of producing JSON null.

Changes

  • Normalize missing datetime values to None in the standard JSON encoder.
  • Fix the orjson serialization path to handle NaT correctly without disabling the fast path for unaffected data.
  • Add regression tests covering datetime units (D, us, ns), multidimensional arrays, both JSON engines, and pandas Series round trips.
  • Update CHANGELOG.md.

Validation

Tested locally on Windows with Python 3.13.14, Plotly 7.1.0, pandas 3.0.6, and NumPy 2.5.4.

  • 330 passed, 1 skipped — tests/test_io and tests/test_optional/test_utils
  • Ruff formatting check passed for all three modified Python files.
  • Full Ruff lint has pre-existing findings; it is not reported as passing.

AI assistance

ChatGPT assisted with investigation, implementation, and regression tests. The reported validation results were obtained from a local Plotly source checkout.

@camdecoster

Copy link
Copy Markdown
Contributor

@camdecoster
camdecoster marked this pull request as draft October 20, 2026 21:33

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: NaT inside a datetime64 array serializes as the string "NaT" instead of null

2 participants