diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ce4580530..6e9a68fd8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/plotly/io/_json.py b/plotly/io/_json.py index 15375632c7..b45191a07b 100644 --- a/plotly/io/_json.py +++ b/plotly/io/_json.py @@ -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"): diff --git a/tests/test_io/test_to_from_plotly_json.py b/tests/test_io/test_to_from_plotly_json.py index 8022bd3b8e..1c0440b033 100644 --- a/tests/test_io/test_to_from_plotly_json.py +++ b/tests/test_io/test_to_from_plotly_json.py @@ -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"