Skip to content
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
10 changes: 7 additions & 3 deletions packages/python/plotly/_plotly_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,19 @@ def encode_as_sage(obj):

@staticmethod
def encode_as_pandas(obj):
"""Attempt to convert pandas.NaT"""
"""Attempt to convert pandas.NaT / pandas.NA"""
pandas = get_module("pandas", should_load=False)
if not pandas:
raise NotEncodable

if obj is pandas.NaT:
return None
else:
raise NotEncodable

# pandas.NA was introduced in pandas 1.0
if hasattr(pandas, "NA") and obj is pandas.NA:
return None

raise NotEncodable

@staticmethod
def encode_as_numpy(obj):
Expand Down
2 changes: 1 addition & 1 deletion packages/python/plotly/plotly/express/_imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def imshow(
binary_string = img.ndim >= (3 + slice_dimensions) and not is_dataframe

# Cast bools to uint8 (also one byte)
if img.dtype == np.bool:
if img.dtype == bool:
img = 255 * img.astype(np.uint8)

if range_color is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def test_automatic_zmax_from_dtype():
np.uint8: 2**8 - 1,
np.uint16: 2**16 - 1,
np.float: 1,
np.bool: 255,
bool: 255,
}
for key, val in dtypes_dict.items():
img = np.array([0, 1], dtype=key)
img = np.dstack((img,) * 3)
fig = px.imshow(img, binary_string=False)
# For uint8 in "infer" mode we don't pass zmin/zmax unless specified
if key in [np.uint8, np.bool]:
if key in [np.uint8, bool]:
assert fig.data[0]["zmax"] is None
else:
assert fig.data[0]["zmax"] == (val, val, val, 255)
Expand Down