Skip to content

Commit 44a52e5

Browse files
committed
merge master and rm FIXME comment
2 parents a22a7be + 6319ab9 commit 44a52e5

17 files changed

+162
-101
lines changed

Diff for: .circleci/config.yml

+9
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

Diff for: packages/python/plotly/_plotly_utils/basevalidators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def copy_to_readonly_numpy_array(v, kind=None, force_numeric=False):
9292
"O": "object",
9393
}
9494

95-
# With `pass_through=True``, the original object will be returned if unable to convert
95+
# With `pass_through=True`, the original object will be returned if unable to convert
9696
# to a Narwhals DataFrame or Series.
9797
v = nw.from_native(v, allow_series=True, pass_through=True)
9898

Diff for: packages/python/plotly/_plotly_utils/tests/validators/test_any_validator.py

+2-1
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

Diff for: packages/python/plotly/_plotly_utils/tests/validators/test_boolean_validator.py

+2-3
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)

Diff for: packages/python/plotly/_plotly_utils/tests/validators/test_enumerated_validator.py

+4-4
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+
from plotly.tests.test_optional.test_utils.test_utils import np_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:

Diff for: packages/python/plotly/_plotly_utils/tests/validators/test_integer_validator.py

+2-2
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+
from plotly.tests.test_optional.test_utils.test_utils import np_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:

Diff for: packages/python/plotly/_plotly_utils/tests/validators/test_number_validator.py

+14-7
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:

Diff for: packages/python/plotly/_plotly_utils/tests/validators/test_string_validator.py

+3-2
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)

Diff for: packages/python/plotly/_plotly_utils/tests/validators/test_subplotid_validator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from _plotly_utils.basevalidators import SubplotidValidator
3-
import numpy as np
3+
from plotly.tests.test_optional.test_utils.test_utils import np_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)

Diff for: packages/python/plotly/plotly/express/_core.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,8 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
412412
# NB this means trendline functions must output one-to-one with the input series
413413
# i.e. we can't do resampling, because then the X values might not line up!
414414
non_missing = ~(x.is_null() | y.is_null())
415-
trace_patch["x"] = (
416-
sorted_trace_data.filter(non_missing).get_column(args["x"])
417-
# FIXME: Converting to numpy is needed to pass `test_trendline_on_timeseries`
418-
# test, but I wonder if it is the right way to do it in the first place.
415+
trace_patch["x"] = sorted_trace_data.filter(non_missing).get_column(
416+
args["x"]
419417
)
420418
if (
421419
trace_patch["x"].dtype == nw.Datetime
@@ -1178,6 +1176,8 @@ def to_unindexed_series(x, name=None, native_namespace=None):
11781176
its index reset if pandas-like). Stripping the index from existing pd.Series is
11791177
required to get things to match up right in the new DataFrame we're building.
11801178
"""
1179+
# With `pass_through=True`, the original object will be returned if unable to convert
1180+
# to a Narwhals Series.
11811181
x = nw.from_native(x, series_only=True, pass_through=True)
11821182
if isinstance(x, nw.Series):
11831183
return nw.maybe_reset_index(x).rename(name)
@@ -1383,6 +1383,8 @@ def process_args_into_dataframe(
13831383
% (field, len_arg, str(list(df_output.keys())), length)
13841384
)
13851385

1386+
# With `pass_through=True`, the original object will be returned if unable to convert
1387+
# to a Narwhals Series.
13861388
df_output[str(col_name)] = to_unindexed_series(
13871389
x=nw.from_native(argument, series_only=True, pass_through=True),
13881390
name=str(col_name),
@@ -1512,7 +1514,7 @@ def build_dataframe(args, constructor):
15121514
is_pd_like = True
15131515

15141516
# data_frame is any other DataFrame object natively supported via Narwhals.
1515-
# With pass_through=True, the original object will be returned if unable to convert
1517+
# With `pass_through=True`, the original object will be returned if unable to convert
15161518
# to a Narwhals DataFrame, making this condition False.
15171519
elif isinstance(
15181520
data_frame := nw.from_native(
@@ -1525,7 +1527,7 @@ def build_dataframe(args, constructor):
15251527
columns = args["data_frame"].columns
15261528

15271529
# data_frame is any other Series object natively supported via Narwhals.
1528-
# With pass_through=True, the original object will be returned if unable to convert
1530+
# With `pass_through=True`, the original object will be returned if unable to convert
15291531
# to a Narwhals Series, making this condition False.
15301532
elif isinstance(
15311533
series := nw.from_native(

Diff for: packages/python/plotly/plotly/tests/test_optional/test_figure_factory/test_figure_factory.py

+13-12
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,

0 commit comments

Comments
 (0)