Skip to content

Commit f673026

Browse files
handle pandas.NA
1 parent b5c4ce2 commit f673026

File tree

1 file changed

+7
-3
lines changed
  • packages/python/plotly/_plotly_utils

1 file changed

+7
-3
lines changed

Diff for: packages/python/plotly/_plotly_utils/utils.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,19 @@ def encode_as_sage(obj):
167167

168168
@staticmethod
169169
def encode_as_pandas(obj):
170-
"""Attempt to convert pandas.NaT"""
170+
"""Attempt to convert pandas.NaT / pandas.NA"""
171171
pandas = get_module("pandas", should_load=False)
172172
if not pandas:
173173
raise NotEncodable
174174

175175
if obj is pandas.NaT:
176176
return None
177-
else:
178-
raise NotEncodable
177+
178+
# pandas.NA was introduced in pandas 1.0
179+
if hasattr(pandas, "NA") and obj is pandas.NA:
180+
return None
181+
182+
raise NotEncodable
179183

180184
@staticmethod
181185
def encode_as_numpy(obj):

0 commit comments

Comments
 (0)