Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6319ab9

Browse files
Merge pull request #4622 from bnavigator/np2
Make test suite ready for NumPy 2.0.0
2 parents fe306ee + c55f5cd commit 6319ab9

File tree

15 files changed

+147
-94
lines changed

15 files changed

+147
-94
lines changed

‎.circleci/config.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ jobs:
249249
- test_optional:
250250
py: "312_no_numpy"
251251

252+
python_312_np2:
253+
docker:
254+
- image: cimg/python:3.12-browsers
255+
steps:
256+
- test_optional:
257+
py: "312_np2"
258+
259+
252260
# Percy
253261
python_39_percy:
254262
docker:
@@ -607,4 +615,5 @@ workflows:
607615
- python_39_pandas_2_optional
608616
- python_39_percy
609617
- python_312_no_numpy
618+
- python_312_np2
610619
- build-doc

‎packages/python/plotly/_plotly_utils/tests/validators/test_any_validator.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
from _plotly_utils.basevalidators import AnyValidator
33
import numpy as np
4+
from plotly.tests.test_optional.test_utils.test_utils import np_nan, np_inf
45

56

67
# Fixtures
@@ -18,7 +19,7 @@ def validator_aok():
1819
# Tests
1920
# -----
2021
# ### Acceptance ###
21-
@pytest.mark.parametrize("val", [set(), "Hello", 123, np.inf, np.nan, {}])
22+
@pytest.mark.parametrize("val", [set(), "Hello", 123, np_inf(), np_nan(), {}])
2223
def test_acceptance(val, validator):
2324
assert validator.validate_coerce(val) is val
2425

‎packages/python/plotly/_plotly_utils/tests/validators/test_boolean_validator.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from _plotly_utils.basevalidators import BooleanValidator
3-
import numpy as np
4-
3+
from plotly.tests.test_optional.test_utils.test_utils import np_nan
54

65
# Boolean Validator
76
# =================
@@ -18,7 +17,7 @@ def test_acceptance(val, validator):
1817

1918

2019
# ### Rejection ###
21-
@pytest.mark.parametrize("val", [1.0, 0.0, "True", "False", [], 0, np.nan])
20+
@pytest.mark.parametrize("val", [1.0, 0.0, "True", "False", [], 0, np_nan()])
2221
def test_rejection(val, validator):
2322
with pytest.raises(ValueError) as validation_failure:
2423
validator.validate_coerce(val)

‎packages/python/plotly/_plotly_utils/tests/validators/test_enumerated_validator.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
import pandas as pd
44
from _plotly_utils.basevalidators import EnumeratedValidator
5-
5+
fromplotly.tests.test_optional.test_utils.test_utilsimportnp_inf
66

77
# Fixtures
88
# --------
@@ -42,7 +42,7 @@ def test_acceptance(val, validator):
4242
# ### Value Rejection ###
4343
@pytest.mark.parametrize(
4444
"val",
45-
[True, 0, 1, 23, np.inf, set(), ["first", "second"], [True], ["third", 4], [4]],
45+
[True, 0, 1, 23, np_inf(), set(), ["first", "second"], [True], ["third", 4], [4]],
4646
)
4747
def test_rejection_by_value(val, validator):
4848
with pytest.raises(ValueError) as validation_failure:
@@ -95,7 +95,7 @@ def test_acceptance_aok(val, validator_aok):
9595

9696

9797
# ### Rejection by value ###
98-
@pytest.mark.parametrize("val", [True, 0, 1, 23, np.inf, set()])
98+
@pytest.mark.parametrize("val", [True, 0, 1, 23, np_inf(), set()])
9999
def test_rejection_by_value_aok(val, validator_aok):
100100
with pytest.raises(ValueError) as validation_failure:
101101
validator_aok.validate_coerce(val)
@@ -105,7 +105,7 @@ def test_rejection_by_value_aok(val, validator_aok):
105105

106106
# ### Reject by elements ###
107107
@pytest.mark.parametrize(
108-
"val", [[True], [0], [1, 23], [np.inf, set()], ["ffirstt", "second", "third"]]
108+
"val", [[True], [0], [1, 23], [np_inf(), set()], ["ffirstt", "second", "third"]]
109109
)
110110
def test_rejection_by_element_aok(val, validator_aok):
111111
with pytest.raises(ValueError) as validation_failure:

‎packages/python/plotly/_plotly_utils/tests/validators/test_integer_validator.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from _plotly_utils.basevalidators import IntegerValidator
66
import numpy as np
77
import pandas as pd
8-
8+
fromplotly.tests.test_optional.test_utils.test_utilsimportnp_nan, np_inf
99

1010
# ### Fixtures ###
1111
@pytest.fixture()
@@ -53,7 +53,7 @@ def test_acceptance(val, validator):
5353

5454
# ### Rejection by value ###
5555
@pytest.mark.parametrize(
56-
"val", ["hello", (), [], [1, 2, 3], set(), "34", np.nan, np.inf, -np.inf]
56+
"val", ["hello", (), [], [1, 2, 3], set(), "34", np_nan(), np_inf(), -np_inf()]
5757
)
5858
def test_rejection_by_value(val, validator):
5959
with pytest.raises(ValueError) as validation_failure:

‎packages/python/plotly/_plotly_utils/tests/validators/test_number_validator.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from _plotly_utils.basevalidators import NumberValidator
55
import numpy as np
66
import pandas as pd
7+
from plotly.tests.test_optional.test_utils.test_utils import np_nan, np_inf
78

89
# Fixtures
910
# --------
@@ -36,7 +37,7 @@ def validator_aok():
3637
# ------------
3738
# ### Acceptance ###
3839
@pytest.mark.parametrize(
39-
"val", [1.0, 0.0, 1, -1234.5678, 54321, np.pi, np.nan, np.inf, -np.inf]
40+
"val", [1.0, 0.0, 1, -1234.5678, 54321, np.pi, np_nan(), np_inf(), -np_inf()]
4041
)
4142
def test_acceptance(val, validator):
4243
assert validator.validate_coerce(val) == approx(val, nan_ok=True)
@@ -57,7 +58,7 @@ def test_acceptance_min_max(val, validator_min_max):
5758
assert validator_min_max.validate_coerce(val) == approx(val)
5859

5960

60-
@pytest.mark.parametrize("val", [-1.01, -10, 2.1, 234, -np.inf, np.nan, np.inf])
61+
@pytest.mark.parametrize("val", [-1.01, -10, 2.1, 234, -np_inf(), np_nan(), np_inf()])
6162
def test_rejection_min_max(val, validator_min_max):
6263
with pytest.raises(ValueError) as validation_failure:
6364
validator_min_max.validate_coerce(val)
@@ -66,12 +67,12 @@ def test_rejection_min_max(val, validator_min_max):
6667

6768

6869
# ### With min only ###
69-
@pytest.mark.parametrize("val", [0, 0.0, -0.5, 99999, np.inf])
70+
@pytest.mark.parametrize("val", [0, 0.0, -0.5, 99999, np_inf()])
7071
def test_acceptance_min(val, validator_min):
7172
assert validator_min.validate_coerce(val) == approx(val)
7273

7374

74-
@pytest.mark.parametrize("val", [-1.01, -np.inf, np.nan])
75+
@pytest.mark.parametrize("val", [-1.01, -np_inf(), np_nan()])
7576
def test_rejection_min(val, validator_min):
7677
with pytest.raises(ValueError) as validation_failure:
7778
validator_min.validate_coerce(val)
@@ -80,12 +81,12 @@ def test_rejection_min(val, validator_min):
8081

8182

8283
# ### With max only ###
83-
@pytest.mark.parametrize("val", [0, 0.0, -np.inf, -123456, np.pi / 2])
84+
@pytest.mark.parametrize("val", [0, 0.0, -np_inf(), -123456, np.pi / 2])
8485
def test_acceptance_max(val, validator_max):
8586
assert validator_max.validate_coerce(val) == approx(val)
8687

8788

88-
@pytest.mark.parametrize("val", [2.01, np.inf, np.nan])
89+
@pytest.mark.parametrize("val", [2.01, np_inf(), np_nan()])
8990
def test_rejection_max(val, validator_max):
9091
with pytest.raises(ValueError) as validation_failure:
9192
validator_max.validate_coerce(val)
@@ -142,7 +143,13 @@ def test_rejection_aok(val, validator_aok):
142143
# ### Rejection by element ###
143144
@pytest.mark.parametrize(
144145
"val",
145-
[[-1.6, 0.0], [1, 1.5, 2], [-0.1234, 0.41, np.nan], [0, np.inf], [0, -np.inf]],
146+
[
147+
[-1.6, 0.0],
148+
[1, 1.5, 2],
149+
[-0.1234, 0.41, np_nan()],
150+
[0, np_inf()],
151+
[0, -np_inf()],
152+
],
146153
)
147154
def test_rejection_aok_min_max(val, validator_aok):
148155
with pytest.raises(ValueError) as validation_failure:

‎packages/python/plotly/_plotly_utils/tests/validators/test_string_validator.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from _plotly_utils.basevalidators import StringValidator
44
import numpy as np
5+
from plotly.tests.test_optional.test_utils.test_utils import np_nan
56

67

78
# Fixtures
@@ -53,7 +54,7 @@ def validator_no_blanks_aok():
5354
# Not strict
5455
# ### Acceptance ###
5556
@pytest.mark.parametrize(
56-
"val", ["bar", 234, np.nan, "HELLO!!!", "world!@#$%^&*()", "", "\u03BC"]
57+
"val", ["bar", 234, np_nan(), "HELLO!!!", "world!@#$%^&*()", "", "\u03BC"]
5758
)
5859
def test_acceptance(val, validator):
5960
expected = str(val) if not isinstance(val, str) else val
@@ -108,7 +109,7 @@ def test_acceptance_strict(val, validator_strict):
108109

109110

110111
# ### Rejection by value ###
111-
@pytest.mark.parametrize("val", [(), [], [1, 2, 3], set(), np.nan, np.pi, 23])
112+
@pytest.mark.parametrize("val", [(), [], [1, 2, 3], set(), np_nan(), np.pi, 23])
112113
def test_rejection_strict(val, validator_strict):
113114
with pytest.raises(ValueError) as validation_failure:
114115
validator_strict.validate_coerce(val)

‎packages/python/plotly/_plotly_utils/tests/validators/test_subplotid_validator.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from _plotly_utils.basevalidators import SubplotidValidator
3-
importnumpyasnp
3+
fromplotly.tests.test_optional.test_utils.test_utilsimportnp_nan, np_inf
44

55

66
# Fixtures
@@ -19,7 +19,7 @@ def test_acceptance(val, validator):
1919

2020

2121
# ### Rejection by type ###
22-
@pytest.mark.parametrize("val", [23, [], {}, set(), np.inf, np.nan])
22+
@pytest.mark.parametrize("val", [23, [], {}, set(), np_inf(), np_nan()])
2323
def test_rejection_type(val, validator):
2424
with pytest.raises(ValueError) as validation_failure:
2525
validator.validate_coerce(val)

‎packages/python/plotly/plotly/tests/test_optional/test_figure_factory/test_figure_factory.py‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import plotly.figure_factory as ff
88
from plotly.tests.test_optional.optional_utils import NumpyTestUtilsMixin
9+
from plotly.tests.test_optional.test_utils.test_utils import np_nan, np_inf
910

1011
import numpy as np
1112
from plotly.tests.utils import TestCaseNoTemplate
@@ -975,10 +976,10 @@ def test_default_dendrogram(self):
975976
],
976977
layout=go.Layout(
977978
autosize=False,
978-
height=np.inf,
979+
height=np_inf(),
979980
hovermode="closest",
980981
showlegend=False,
981-
width=np.inf,
982+
width=np_inf(),
982983
xaxis=go.layout.XAxis(
983984
mirror="allticks",
984985
rangemode="tozero",
@@ -1062,10 +1063,10 @@ def test_dendrogram_random_matrix(self):
10621063
],
10631064
layout=go.Layout(
10641065
autosize=False,
1065-
height=np.inf,
1066+
height=np_inf(),
10661067
hovermode="closest",
10671068
showlegend=False,
1068-
width=np.inf,
1069+
width=np_inf(),
10691070
xaxis=go.layout.XAxis(
10701071
mirror="allticks",
10711072
rangemode="tozero",
@@ -1217,10 +1218,10 @@ def test_dendrogram_colorscale(self):
12171218
],
12181219
layout=go.Layout(
12191220
autosize=False,
1220-
height=np.inf,
1221+
height=np_inf(),
12211222
hovermode="closest",
12221223
showlegend=False,
1223-
width=np.inf,
1224+
width=np_inf(),
12241225
xaxis=go.layout.XAxis(
12251226
mirror="allticks",
12261227
rangemode="tozero",
@@ -4118,25 +4119,25 @@ def test_full_choropleth(self):
41184119
-88.02432999999999,
41194120
-88.04504299999999,
41204121
-88.053375,
4121-
np.nan,
4122+
np_nan(),
41224123
-88.211209,
41234124
-88.209999,
41244125
-88.208733,
41254126
-88.209559,
41264127
-88.211209,
4127-
np.nan,
4128+
np_nan(),
41284129
-88.22511999999999,
41294130
-88.22128099999999,
41304131
-88.218694,
41314132
-88.22465299999999,
41324133
-88.22511999999999,
4133-
np.nan,
4134+
np_nan(),
41344135
-88.264659,
41354136
-88.25782699999999,
41364137
-88.25947,
41374138
-88.255659,
41384139
-88.264659,
4139-
np.nan,
4140+
np_nan(),
41404141
-88.327302,
41414142
-88.20146799999999,
41424143
-88.141143,
@@ -4146,13 +4147,13 @@ def test_full_choropleth(self):
41464147
-88.10665399999999,
41474148
-88.149812,
41484149
-88.327302,
4149-
np.nan,
4150+
np_nan(),
41504151
-88.346745,
41514152
-88.341235,
41524153
-88.33288999999999,
41534154
-88.346823,
41544155
-88.346745,
4155-
np.nan,
4156+
np_nan(),
41564157
-88.473227,
41574158
-88.097888,
41584159
-88.154617,

‎packages/python/plotly/plotly/tests/test_optional/test_px/test_imshow.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import base64
88
import datetime
99
from plotly.express.imshow_utils import rescale_intensity
10+
from plotly.tests.test_optional.test_utils.test_utils import np_nan
1011

1112
img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]]], dtype=np.uint8)
1213
img_gray = np.arange(100, dtype=float).reshape((10, 10))
@@ -111,7 +112,7 @@ def test_nan_inf_data(binary_string):
111112
zmaxs = [1, 255]
112113
for zmax, img in zip(zmaxs, imgs):
113114
img[0] = 0
114-
img[10:12] = np.nan
115+
img[10:12] = np_nan()
115116
# the case of 2d/heatmap is handled gracefully by the JS trace but I don't know how to check it
116117
fig = px.imshow(
117118
np.dstack((img,) * 3),
@@ -341,7 +342,7 @@ def test_imshow_source_dtype_zmax(dtype, contrast_rescaling):
341342
assert (
342343
np.abs(
343344
np.max(decode_image_string(fig.data[0].source))
344-
- 255 * img.max() / np.iinfo(dtype).max
345+
- np.int64(255) * img.max() / np.iinfo(dtype).max
345346
)
346347
< 1
347348
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /