Skip to content

Commit b3ed838

Browse files
committed
Fix failing tests
- Removes a speed comparison that is no longer needed because the base64 encoding makes it faster - Updates a test to use numpy arrays to account for plotly express automatically converting numerical lists to pandas arrays. - Remove unnecessary enumerate
1 parent bd0a2d3 commit b3ed838

File tree

3 files changed

+4
-36
lines changed

3 files changed

+4
-36
lines changed

packages/python/plotly/_plotly_utils/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def convert_to_base64(obj):
109109
else:
110110
convert_to_base64(value)
111111
elif isinstance(obj, list) or isinstance(obj, tuple):
112-
for i, value in enumerate(obj):
112+
for value in obj:
113113
convert_to_base64(value)
114114

115115

packages/python/plotly/plotly/tests/test_optional/test_px/test_px_functions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def _compare_figures(go_trace, px_fig):
2525
def test_pie_like_px():
2626
# Pie
2727
labels = ["Oxygen", "Hydrogen", "Carbon_Dioxide", "Nitrogen"]
28-
values = [4500, 2500, 1053, 500]
28+
values = np.array([4500, 2500, 1053, 500])
2929

3030
fig = px.pie(names=labels, values=values)
3131
trace = go.Pie(labels=labels, values=values)
3232
_compare_figures(trace, fig)
3333

3434
labels = ["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"]
3535
parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"]
36-
values = [10, 14, 12, 10, 2, 6, 6, 4, 4]
36+
values = np.array([10, 14, 12, 10, 2, 6, 6, 4, 4])
3737
# Sunburst
3838
fig = px.sunburst(names=labels, parents=parents, values=values)
3939
trace = go.Sunburst(labels=labels, parents=parents, values=values)
@@ -45,7 +45,7 @@ def test_pie_like_px():
4545

4646
# Funnel
4747
x = ["A", "B", "C"]
48-
y = [3, 2, 1]
48+
y = np.array([3, 2, 1])
4949
fig = px.funnel(y=y, x=x)
5050
trace = go.Funnel(y=y, x=x)
5151
_compare_figures(trace, fig)

packages/python/plotly/plotly/tests/test_optional/test_utils/test_utils.py

-32
Original file line numberDiff line numberDiff line change
@@ -372,38 +372,6 @@ def test_invalid_encode_exception(self):
372372
with self.assertRaises(TypeError):
373373
_json.dumps({"a": {1}}, cls=utils.PlotlyJSONEncoder)
374374

375-
def test_fast_track_finite_arrays(self):
376-
# if NaN or Infinity is found in the json dump
377-
# of a figure, it is decoded and re-encoded to replace these values
378-
# with null. This test checks that NaN and Infinity values are
379-
# indeed converted to null, and that the encoding of figures
380-
# without inf or nan is faster (because we can avoid decoding
381-
# and reencoding).
382-
z = np.random.randn(100, 100)
383-
x = np.arange(100.0)
384-
fig_1 = go.Figure(go.Heatmap(z=z, x=x))
385-
t1 = time()
386-
json_str_1 = _json.dumps(fig_1, cls=utils.PlotlyJSONEncoder)
387-
t2 = time()
388-
x[0] = np.nan
389-
x[1] = np.inf
390-
fig_2 = go.Figure(go.Heatmap(z=z, x=x))
391-
t3 = time()
392-
json_str_2 = _json.dumps(fig_2, cls=utils.PlotlyJSONEncoder)
393-
t4 = time()
394-
assert t2 - t1 < t4 - t3
395-
assert "null" in json_str_2
396-
assert "NaN" not in json_str_2
397-
assert "Infinity" not in json_str_2
398-
x = np.arange(100.0)
399-
fig_3 = go.Figure(go.Heatmap(z=z, x=x))
400-
fig_3.update_layout(title_text="Infinity")
401-
t5 = time()
402-
json_str_3 = _json.dumps(fig_3, cls=utils.PlotlyJSONEncoder)
403-
t6 = time()
404-
assert t2 - t1 < t6 - t5
405-
assert "Infinity" in json_str_3
406-
407375

408376
class TestNumpyIntegerBaseType(TestCase):
409377
def test_numpy_integer_import(self):

0 commit comments

Comments
 (0)