From 7b90bb60064cb0ff3761c0990bacc6b433b3b59f Mon Sep 17 00:00:00 2001 From: David Katz <41651296+DavidKatz-il@users.noreply.github.com> Date: Sun, 16 Feb 2025 16:15:49 +0000 Subject: [PATCH 1/2] Handle pd.NA in clean_to_json_compatible --- plotly/io/_json.py | 2 +- tests/test_io/test_to_from_plotly_json.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plotly/io/_json.py b/plotly/io/_json.py index 15375632c7a..b45191a07b2 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 8022bd3b8e3..1c0440b0330 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" From 775734e89af3d8b29b9456427fc5651243bd5bf5 Mon Sep 17 00:00:00 2001 From: David Katz <41651296+DavidKatz-il@users.noreply.github.com> Date: Sun, 16 Feb 2025 16:26:10 +0000 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ce45805309..6e9a68fd8de 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