Skip to content

Commit 7b90bb6

Browse files
committed
Handle pd.NA in clean_to_json_compatible
1 parent 3850056 commit 7b90bb6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

plotly/io/_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def clean_to_json_compatible(obj, **kwargs):
529529

530530
# pandas
531531
if pd is not None:
532-
if obj is pd.NaT:
532+
if obj is pd.NaT or obj is pd.NA:
533533
return None
534534
elif isinstance(obj, (pd.Series, pd.DatetimeIndex)):
535535
if numpy_allowed and obj.dtype.kind in ("b", "i", "u", "f"):

tests/test_io/test_to_from_plotly_json.py

+6
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,9 @@ def test_sanitize_json(engine):
260260
for bad, good in replacements.items():
261261
assert bad not in fig_json
262262
assert good in fig_json
263+
264+
265+
@pytest.mark.parametrize("na_value", [np.nan, pd.NaT, pd.NA])
266+
def test_na_values(engine, na_value):
267+
result = pio.to_json_plotly(na_value, engine=engine)
268+
assert result == "null"

0 commit comments

Comments
 (0)