Skip to content

Compatibility with evolving PyData libraries #3705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2022
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