Skip to content

Commit ca90f21

Browse files
committed
skip b64 encoding if array is empty
1 parent ac9ddce commit ca90f21

File tree

1 file changed

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

1 file changed

+7
-5
lines changed

packages/python/plotly/_plotly_utils/utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ def to_typed_array_spec(v):
4343
"""
4444
v = copy_to_readonly_numpy_array(v)
4545

46+
# Skip b64 encoding if numpy is not installed,
47+
# or if v is not a numpy array, or if v is empty
4648
np = get_module("numpy", should_load=False)
47-
if not np or not isinstance(v, np.ndarray):
49+
if not np or not isinstance(v, np.ndarray) or v.size == 0:
4850
return v
4951

5052
dtype = str(v.dtype)
5153

5254
# convert default Big Ints until we could support them in plotly.js
5355
if dtype == "int64":
54-
max = v.max() if v.size > 0 else 0
55-
min = v.min() if v.size > 0 else 0
56+
max = v.max()
57+
min = v.min()
5658
if max <= int8max and min >= int8min:
5759
v = v.astype("int8")
5860
elif max <= int16max and min >= int16min:
@@ -63,8 +65,8 @@ def to_typed_array_spec(v):
6365
return v
6466

6567
elif dtype == "uint64":
66-
max = v.max() if v.size > 0 else 0
67-
min = v.min() if v.size > 0 else 0
68+
max = v.max()
69+
min = v.min()
6870
if max <= uint8max and min >= 0:
6971
v = v.astype("uint8")
7072
elif max <= uint16max and min >= 0:

0 commit comments

Comments
 (0)