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

.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/basevalidators.py

Lines changed: 1 addition & 1 deletion
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

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

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

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-
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)

packages/python/plotly/plotly/express/_core.py

Lines changed: 8 additions & 6 deletions
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(

0 commit comments

Comments
 (0)