Skip to content

Commit 4932cdb

Browse files
committed
Remove px tests (duplicates)
1 parent 3702686 commit 4932cdb

File tree

1 file changed

+41
-86
lines changed

1 file changed

+41
-86
lines changed

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

Lines changed: 41 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
import unittest.mock as mock
88
from plotly.express._core import build_dataframe
99
from pandas.testing import assert_frame_equal
10-
from plotly.tests.b64 import b64, _b64
1110
import sys
1211
import warnings
13-
import time
1412

15-
np.random.seed(0)
1613

1714
# Fixtures
1815
# --------
@@ -31,9 +28,8 @@ def add_interchange_module_for_old_pandas():
3128

3229
def test_numpy():
3330
fig = px.scatter(x=[1, 2, 3], y=[2, 3, 4], color=[1, 3, 9])
34-
35-
assert np.all(fig.data[0].x == b64(np.array([1, 2, 3])))
36-
assert np.all(fig.data[0].y == b64(np.array([2, 3, 4])))
31+
assert np.all(fig.data[0].x == np.array([1, 2, 3]))
32+
assert np.all(fig.data[0].y == np.array([2, 3, 4]))
3733
assert np.all(fig.data[0].marker.color == np.array([1, 3, 9]))
3834

3935

@@ -105,16 +101,16 @@ def test_several_dataframes():
105101
df = pd.DataFrame(dict(x=[0, 1], y=[3, 4]))
106102
df2 = pd.DataFrame(dict(x=[3, 5], y=[23, 24]))
107103
fig = px.scatter(x=df.y, y=df2.y)
108-
assert np.all(fig.data[0].x == b64(np.array([3, 4])))
109-
assert np.all(fig.data[0].y == b64(np.array([23, 24])))
104+
assert np.all(fig.data[0].x == np.array([3, 4]))
105+
assert np.all(fig.data[0].y == np.array([23, 24]))
110106
assert fig.data[0].hovertemplate == "x=%{x}<br>y=%{y}<extra></extra>"
111107

112108
df = pd.DataFrame(dict(x=[0, 1], y=[3, 4]))
113109
df2 = pd.DataFrame(dict(x=[3, 5], y=[23, 24]))
114110
df3 = pd.DataFrame(dict(y=[0.1, 0.2]))
115111
fig = px.scatter(x=df.y, y=df2.y, size=df3.y)
116-
assert np.all(fig.data[0].x == b64(np.array([3, 4])))
117-
assert np.all(fig.data[0].y == b64(np.array([23, 24])))
112+
assert np.all(fig.data[0].x == np.array([3, 4]))
113+
assert np.all(fig.data[0].y == np.array([23, 24]))
118114
assert (
119115
fig.data[0].hovertemplate
120116
== "x=%{x}<br>y=%{y}<br>size=%{marker.size}<extra></extra>"
@@ -124,8 +120,8 @@ def test_several_dataframes():
124120
df2 = pd.DataFrame(dict(x=[3, 5], y=[23, 24]))
125121
df3 = pd.DataFrame(dict(y=[0.1, 0.2]))
126122
fig = px.scatter(x=df.y, y=df2.y, hover_data=[df3.y])
127-
assert np.all(fig.data[0].x == b64(np.array([3, 4])))
128-
assert np.all(fig.data[0].y == b64(np.array([23, 24])))
123+
assert np.all(fig.data[0].x == np.array([3, 4]))
124+
assert np.all(fig.data[0].y == np.array([23, 24]))
129125
assert (
130126
fig.data[0].hovertemplate
131127
== "x=%{x}<br>y=%{y}<br>hover_data_0=%{customdata[0]}<extra></extra>"
@@ -135,57 +131,11 @@ def test_several_dataframes():
135131
def test_name_heuristics():
136132
df = pd.DataFrame(dict(x=[0, 1], y=[3, 4], z=[0.1, 0.2]))
137133
fig = px.scatter(df, x=df.y, y=df.x, size=df.y)
138-
assert np.all(fig.data[0].x == b64(np.array([3, 4])))
139-
assert np.all(fig.data[0].y == b64(np.array([0, 1])))
134+
assert np.all(fig.data[0].x == np.array([3, 4]))
135+
assert np.all(fig.data[0].y == np.array([0, 1]))
140136
assert fig.data[0].hovertemplate == "y=%{marker.size}<br>x=%{y}<extra></extra>"
141137

142138

143-
def test_performance_b64():
144-
np_arr_1 = np.random.random(1000000)
145-
np_arr_2 = np.random.random(1000000)
146-
147-
# Test the performance of the base64 arrays
148-
np_arr_start = time.time()
149-
fig = px.scatter(x=np_arr_1, y=np_arr_2, width=800, height=800)
150-
fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
151-
np_arr_time_elapsed = time.time() - np_arr_start
152-
153-
# Test the performance of the raw arrays
154-
list_start = time.time()
155-
fig = px.scatter(x=np_arr_1.tolist(), y=np_arr_2.tolist(), width=800, height=800)
156-
fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
157-
list_time_elapsed = time.time() - list_start
158-
159-
# b64 should be faster than raw
160-
assert (np_arr_time_elapsed / list_time_elapsed) < 0.7
161-
162-
163-
def test_size_performance_b64_uint8():
164-
np_arr_1 = np.random.randint(0, high=254, size=100000, dtype="uint8")
165-
np_arr_2 = np.random.randint(0, high=254, size=100000, dtype="uint8")
166-
167-
# Compare the size of figures with b64 arrays and raw arrays
168-
fig_np_arr = px.scatter(x=np_arr_1, y=np_arr_2)
169-
size_np_arr = fig_np_arr.to_json().__sizeof__()
170-
fig_list = px.scatter(x=np_arr_1.tolist(), y=np_arr_2.tolist())
171-
size_list = fig_list.to_json().__sizeof__()
172-
173-
assert size_list - size_np_arr > 250000
174-
175-
176-
def test_size_performance_b64_float32():
177-
np_arr_1 = np.random.random(100000).astype("float32")
178-
np_arr_2 = np.random.random(100000).astype("float32")
179-
180-
# Compare the size of figures with b64 arrays and raw arrays
181-
fig_np_arr = px.scatter(x=np_arr_1, y=np_arr_2)
182-
size_np_arr = fig_np_arr.to_json().__sizeof__()
183-
fig_list = px.scatter(x=np_arr_1.tolist(), y=np_arr_2.tolist())
184-
size_list = fig_list.to_json().__sizeof__()
185-
186-
assert size_list - size_np_arr > 250000
187-
188-
189139
def test_repeated_name():
190140
iris = px.data.iris()
191141
fig = px.scatter(
@@ -455,27 +405,27 @@ def test_splom_case():
455405
assert len(fig.data[0].dimensions) == len(iris.columns)
456406
dic = {"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}
457407
fig = px.scatter_matrix(dic)
458-
assert np.all(fig.data[0].dimensions[0].values == b64(np.array(dic["a"])))
408+
assert np.all(fig.data[0].dimensions[0].values == np.array(dic["a"]))
459409
ar = np.arange(9).reshape((3, 3))
460410
fig = px.scatter_matrix(ar)
461-
assert np.all(fig.data[0].dimensions[0].values == b64(ar[:, 0]))
411+
assert np.all(fig.data[0].dimensions[0].values == ar[:, 0])
462412

463413

464414
def test_int_col_names():
465415
# DataFrame with int column names
466416
lengths = pd.DataFrame(np.random.random(100))
467417
fig = px.histogram(lengths, x=0)
468-
assert np.all(b64(np.array(lengths).flatten()) == fig.data[0].x)
418+
assert np.all(np.array(lengths).flatten() == fig.data[0].x)
469419
# Numpy array
470420
ar = np.arange(100).reshape((10, 10))
471421
fig = px.scatter(ar, x=2, y=8)
472-
assert np.all(fig.data[0].x == b64(ar[:, 2]))
422+
assert np.all(fig.data[0].x == ar[:, 2])
473423

474424

475425
def test_data_frame_from_dict():
476426
fig = px.scatter({"time": [0, 1], "money": [1, 2]}, x="time", y="money")
477427
assert fig.data[0].hovertemplate == "time=%{x}<br>money=%{y}<extra></extra>"
478-
assert np.all(fig.data[0].x == _b64([0, 1]))
428+
assert np.all(fig.data[0].x == [0, 1])
479429

480430

481431
def test_arguments_not_modified():
@@ -539,11 +489,13 @@ def test_identity_map():
539489

540490
def test_constants():
541491
fig = px.scatter(x=px.Constant(1), y=[1, 2])
542-
assert fig.data[0].x == _b64([1, 1])
492+
assert fig.data[0].x[0] == 1
493+
assert fig.data[0].x[1] == 1
543494
assert "x=" in fig.data[0].hovertemplate
544495

545496
fig = px.scatter(x=px.Constant(1, label="time"), y=[1, 2])
546-
assert fig.data[0].x == _b64([1, 1])
497+
assert fig.data[0].x[0] == 1
498+
assert fig.data[0].x[1] == 1
547499
assert "x=" not in fig.data[0].hovertemplate
548500
assert "time=" in fig.data[0].hovertemplate
549501

@@ -567,12 +519,15 @@ def test_constants():
567519

568520
def test_ranges():
569521
fig = px.scatter(x=px.Range(), y=[1, 2], hover_data=[px.Range()])
570-
assert fig.data[0].x == _b64([0, 1])
571-
assert fig.data[0].customdata == _b64([[0], [1]])
522+
assert fig.data[0].x[0] == 0
523+
assert fig.data[0].x[1] == 1
524+
assert fig.data[0].customdata[0][0] == 0
525+
assert fig.data[0].customdata[1][0] == 1
572526
assert "x=" in fig.data[0].hovertemplate
573527

574528
fig = px.scatter(x=px.Range(label="time"), y=[1, 2])
575-
assert fig.data[0].x == _b64([0, 1])
529+
assert fig.data[0].x[0] == 0
530+
assert fig.data[0].x[1] == 1
576531
assert "x=" not in fig.data[0].hovertemplate
577532
assert "time=" in fig.data[0].hovertemplate
578533

@@ -662,55 +617,55 @@ def test_x_or_y(fn):
662617
categorical_df = pd.DataFrame(dict(col=categorical), index=index)
663618

664619
fig = fn(x=numerical)
665-
assert fig.data[0].x == _b64(numerical)
666-
assert fig.data[0].y == _b64(range_4)
620+
assert list(fig.data[0].x) == numerical
621+
assert list(fig.data[0].y) == range_4
667622
assert fig.data[0].orientation == "h"
668623
fig = fn(y=numerical)
669-
assert fig.data[0].x == _b64(range_4)
670-
assert fig.data[0].y == _b64(numerical)
624+
assert list(fig.data[0].x) == range_4
625+
assert list(fig.data[0].y) == numerical
671626
assert fig.data[0].orientation == "v"
672627
fig = fn(numerical_df, x="col")
673-
assert fig.data[0].x == _b64(numerical)
674-
assert fig.data[0].y == _b64(index)
628+
assert list(fig.data[0].x) == numerical
629+
assert list(fig.data[0].y) == index
675630
assert fig.data[0].orientation == "h"
676631
fig = fn(numerical_df, y="col")
677-
assert fig.data[0].x == _b64(index)
678-
assert fig.data[0].y == _b64(numerical)
632+
assert list(fig.data[0].x) == index
633+
assert list(fig.data[0].y) == numerical
679634
assert fig.data[0].orientation == "v"
680635

681636
if fn != px.bar:
682637
fig = fn(x=categorical)
683638
assert list(fig.data[0].x) == categorical
684-
assert fig.data[0].y == _b64(range_4)
639+
assert list(fig.data[0].y) == range_4
685640
assert fig.data[0].orientation == "h"
686641
fig = fn(y=categorical)
687-
assert fig.data[0].x == _b64(range_4)
642+
assert list(fig.data[0].x) == range_4
688643
assert list(fig.data[0].y) == categorical
689644
assert fig.data[0].orientation == "v"
690645
fig = fn(categorical_df, x="col")
691646
assert list(fig.data[0].x) == categorical
692-
assert fig.data[0].y == _b64(index)
647+
assert list(fig.data[0].y) == index
693648
assert fig.data[0].orientation == "h"
694649
fig = fn(categorical_df, y="col")
695-
assert fig.data[0].x == _b64(index)
650+
assert list(fig.data[0].x) == index
696651
assert list(fig.data[0].y) == categorical
697652
assert fig.data[0].orientation == "v"
698653

699654
else:
700655
fig = fn(x=categorical)
701656
assert list(fig.data[0].x) == categorical
702-
assert fig.data[0].y == _b64(constant)
657+
assert list(fig.data[0].y) == constant
703658
assert fig.data[0].orientation == "v"
704659
fig = fn(y=categorical)
705-
assert fig.data[0].x == _b64(constant)
660+
assert list(fig.data[0].x) == constant
706661
assert list(fig.data[0].y) == categorical
707662
assert fig.data[0].orientation == "h"
708663
fig = fn(categorical_df, x="col")
709664
assert list(fig.data[0].x) == categorical
710-
assert fig.data[0].y == _b64(constant)
665+
assert list(fig.data[0].y) == constant
711666
assert fig.data[0].orientation == "v"
712667
fig = fn(categorical_df, y="col")
713-
assert fig.data[0].x == _b64(constant)
668+
assert list(fig.data[0].x) == constant
714669
assert list(fig.data[0].y) == categorical
715670
assert fig.data[0].orientation == "h"
716671

0 commit comments

Comments
 (0)