Skip to content

Fix TypeError: When using orjson and serializing pandas.NA #5040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [6.0.1] - 2025-02-16

### Fixed
- Fix `TypeError` when using `orjson` to serialize `pandas.NA`.

## [6.0.0] - 2025-01-28

### Added
Expand Down
2 changes: 1 addition & 1 deletion plotly/io/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def clean_to_json_compatible(obj, **kwargs):

# pandas
if pd is not None:
if obj is pd.NaT:
if obj is pd.NaT or obj is pd.NA:
return None
elif isinstance(obj, (pd.Series, pd.DatetimeIndex)):
if numpy_allowed and obj.dtype.kind in ("b", "i", "u", "f"):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_io/test_to_from_plotly_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,9 @@ def test_sanitize_json(engine):
for bad, good in replacements.items():
assert bad not in fig_json
assert good in fig_json


@pytest.mark.parametrize("na_value", [np.nan, pd.NaT, pd.NA])
def test_na_values(engine, na_value):
result = pio.to_json_plotly(na_value, engine=engine)
assert result == "null"