Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ jobs:
- test_optional:
py: "312_no_numpy"

python_312_np2:
docker:
- image: cimg/python:3.12-browsers
steps:
- test_optional:
py: "312_np2"


# Percy
python_39_percy:
docker:
Expand Down Expand Up @@ -607,4 +615,5 @@ workflows:
- python_39_pandas_2_optional
- python_39_percy
- python_312_no_numpy
- python_312_np2
- build-doc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from _plotly_utils.basevalidators import AnyValidator
import numpy as np
from plotly.tests.test_optional.test_utils.test_utils import np_nan, np_inf


# Fixtures
Expand All @@ -18,7 +19,7 @@ def validator_aok():
# Tests
# -----
# ### Acceptance ###
@pytest.mark.parametrize("val", [set(), "Hello", 123, np.inf, np.nan, {}])
@pytest.mark.parametrize("val", [set(), "Hello", 123, np_inf(), np_nan(), {}])
def test_acceptance(val, validator):
assert validator.validate_coerce(val) is val

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from _plotly_utils.basevalidators import BooleanValidator
import numpy as np

from plotly.tests.test_optional.test_utils.test_utils import np_nan

# Boolean Validator
# =================
Expand All @@ -18,7 +17,7 @@ def test_acceptance(val, validator):


# ### Rejection ###
@pytest.mark.parametrize("val", [1.0, 0.0, "True", "False", [], 0, np.nan])
@pytest.mark.parametrize("val", [1.0, 0.0, "True", "False", [], 0, np_nan()])
def test_rejection(val, validator):
with pytest.raises(ValueError) as validation_failure:
validator.validate_coerce(val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import pandas as pd
from _plotly_utils.basevalidators import EnumeratedValidator

from plotly.tests.test_optional.test_utils.test_utils import np_inf

# Fixtures
# --------
Expand Down Expand Up @@ -42,7 +42,7 @@ def test_acceptance(val, validator):
# ### Value Rejection ###
@pytest.mark.parametrize(
"val",
[True, 0, 1, 23, np.inf, set(), ["first", "second"], [True], ["third", 4], [4]],
[True, 0, 1, 23, np_inf(), set(), ["first", "second"], [True], ["third", 4], [4]],
)
def test_rejection_by_value(val, validator):
with pytest.raises(ValueError) as validation_failure:
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_acceptance_aok(val, validator_aok):


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

# ### Reject by elements ###
@pytest.mark.parametrize(
"val", [[True], [0], [1, 23], [np.inf, set()], ["ffirstt", "second", "third"]]
"val", [[True], [0], [1, 23], [np_inf(), set()], ["ffirstt", "second", "third"]]
)
def test_rejection_by_element_aok(val, validator_aok):
with pytest.raises(ValueError) as validation_failure:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from _plotly_utils.basevalidators import IntegerValidator
import numpy as np
import pandas as pd

from plotly.tests.test_optional.test_utils.test_utils import np_nan, np_inf

# ### Fixtures ###
@pytest.fixture()
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_acceptance(val, validator):

# ### Rejection by value ###
@pytest.mark.parametrize(
"val", ["hello", (), [], [1, 2, 3], set(), "34", np.nan, np.inf, -np.inf]
"val", ["hello", (), [], [1, 2, 3], set(), "34", np_nan(), np_inf(), -np_inf()]
)
def test_rejection_by_value(val, validator):
with pytest.raises(ValueError) as validation_failure:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from _plotly_utils.basevalidators import NumberValidator
import numpy as np
import pandas as pd
from plotly.tests.test_optional.test_utils.test_utils import np_nan, np_inf

# Fixtures
# --------
Expand Down Expand Up @@ -36,7 +37,7 @@ def validator_aok():
# ------------
# ### Acceptance ###
@pytest.mark.parametrize(
"val", [1.0, 0.0, 1, -1234.5678, 54321, np.pi, np.nan, np.inf, -np.inf]
"val", [1.0, 0.0, 1, -1234.5678, 54321, np.pi, np_nan(), np_inf(), -np_inf()]
)
def test_acceptance(val, validator):
assert validator.validate_coerce(val) == approx(val, nan_ok=True)
Expand All @@ -57,7 +58,7 @@ def test_acceptance_min_max(val, validator_min_max):
assert validator_min_max.validate_coerce(val) == approx(val)


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


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


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


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


@pytest.mark.parametrize("val", [2.01, np.inf, np.nan])
@pytest.mark.parametrize("val", [2.01, np_inf(), np_nan()])
def test_rejection_max(val, validator_max):
with pytest.raises(ValueError) as validation_failure:
validator_max.validate_coerce(val)
Expand Down Expand Up @@ -142,7 +143,13 @@ def test_rejection_aok(val, validator_aok):
# ### Rejection by element ###
@pytest.mark.parametrize(
"val",
[[-1.6, 0.0], [1, 1.5, 2], [-0.1234, 0.41, np.nan], [0, np.inf], [0, -np.inf]],
[
[-1.6, 0.0],
[1, 1.5, 2],
[-0.1234, 0.41, np_nan()],
[0, np_inf()],
[0, -np_inf()],
],
)
def test_rejection_aok_min_max(val, validator_aok):
with pytest.raises(ValueError) as validation_failure:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from _plotly_utils.basevalidators import StringValidator
import numpy as np
from plotly.tests.test_optional.test_utils.test_utils import np_nan


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


# ### Rejection by value ###
@pytest.mark.parametrize("val", [(), [], [1, 2, 3], set(), np.nan, np.pi, 23])
@pytest.mark.parametrize("val", [(), [], [1, 2, 3], set(), np_nan(), np.pi, 23])
def test_rejection_strict(val, validator_strict):
with pytest.raises(ValueError) as validation_failure:
validator_strict.validate_coerce(val)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from _plotly_utils.basevalidators import SubplotidValidator
import numpy as np
from plotly.tests.test_optional.test_utils.test_utils import np_nan, np_inf


# Fixtures
Expand All @@ -19,7 +19,7 @@ def test_acceptance(val, validator):


# ### Rejection by type ###
@pytest.mark.parametrize("val", [23, [], {}, set(), np.inf, np.nan])
@pytest.mark.parametrize("val", [23, [], {}, set(), np_inf(), np_nan()])
def test_rejection_type(val, validator):
with pytest.raises(ValueError) as validation_failure:
validator.validate_coerce(val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import plotly.figure_factory as ff
from plotly.tests.test_optional.optional_utils import NumpyTestUtilsMixin
from plotly.tests.test_optional.test_utils.test_utils import np_nan, np_inf

import numpy as np
from plotly.tests.utils import TestCaseNoTemplate
Expand Down Expand Up @@ -975,10 +976,10 @@ def test_default_dendrogram(self):
],
layout=go.Layout(
autosize=False,
height=np.inf,
height=np_inf(),
hovermode="closest",
showlegend=False,
width=np.inf,
width=np_inf(),
xaxis=go.layout.XAxis(
mirror="allticks",
rangemode="tozero",
Expand Down Expand Up @@ -1062,10 +1063,10 @@ def test_dendrogram_random_matrix(self):
],
layout=go.Layout(
autosize=False,
height=np.inf,
height=np_inf(),
hovermode="closest",
showlegend=False,
width=np.inf,
width=np_inf(),
xaxis=go.layout.XAxis(
mirror="allticks",
rangemode="tozero",
Expand Down Expand Up @@ -1217,10 +1218,10 @@ def test_dendrogram_colorscale(self):
],
layout=go.Layout(
autosize=False,
height=np.inf,
height=np_inf(),
hovermode="closest",
showlegend=False,
width=np.inf,
width=np_inf(),
xaxis=go.layout.XAxis(
mirror="allticks",
rangemode="tozero",
Expand Down Expand Up @@ -4118,25 +4119,25 @@ def test_full_choropleth(self):
-88.02432999999999,
-88.04504299999999,
-88.053375,
np.nan,
np_nan(),
-88.211209,
-88.209999,
-88.208733,
-88.209559,
-88.211209,
np.nan,
np_nan(),
-88.22511999999999,
-88.22128099999999,
-88.218694,
-88.22465299999999,
-88.22511999999999,
np.nan,
np_nan(),
-88.264659,
-88.25782699999999,
-88.25947,
-88.255659,
-88.264659,
np.nan,
np_nan(),
-88.327302,
-88.20146799999999,
-88.141143,
Expand All @@ -4146,13 +4147,13 @@ def test_full_choropleth(self):
-88.10665399999999,
-88.149812,
-88.327302,
np.nan,
np_nan(),
-88.346745,
-88.341235,
-88.33288999999999,
-88.346823,
-88.346745,
np.nan,
np_nan(),
-88.473227,
-88.097888,
-88.154617,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import base64
import datetime
from plotly.express.imshow_utils import rescale_intensity
from plotly.tests.test_optional.test_utils.test_utils import np_nan

img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]]], dtype=np.uint8)
img_gray = np.arange(100, dtype=float).reshape((10, 10))
Expand Down Expand Up @@ -111,7 +112,7 @@ def test_nan_inf_data(binary_string):
zmaxs = [1, 255]
for zmax, img in zip(zmaxs, imgs):
img[0] = 0
img[10:12] = np.nan
img[10:12] = np_nan()
# the case of 2d/heatmap is handled gracefully by the JS trace but I don't know how to check it
fig = px.imshow(
np.dstack((img,) * 3),
Expand Down Expand Up @@ -341,7 +342,7 @@ def test_imshow_source_dtype_zmax(dtype, contrast_rescaling):
assert (
np.abs(
np.max(decode_image_string(fig.data[0].source))
- 255 * img.max() / np.iinfo(dtype).max
- np.int64(255) * img.max() / np.iinfo(dtype).max
)
< 1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pandas as pd
import pytest
from datetime import datetime
from plotly.tests.test_optional.test_utils.test_utils import np_nan


@pytest.mark.parametrize(
Expand Down Expand Up @@ -65,7 +66,7 @@ def test_trendline_enough_values(mode, options):
assert len(fig.data) == 2
assert fig.data[1].x is None
fig = px.scatter(
x=[0, 1], y=np.array([0, np.nan]), trendline=mode, trendline_options=options
x=[0, 1], y=np.array([0, np_nan()]), trendline=mode, trendline_options=options
)
assert len(fig.data) == 2
assert fig.data[1].x is None
Expand All @@ -75,8 +76,8 @@ def test_trendline_enough_values(mode, options):
assert len(fig.data) == 2
assert fig.data[1].x is None
fig = px.scatter(
x=np.array([0, 1, np.nan]),
y=np.array([0, np.nan, 1]),
x=np.array([0, 1, np_nan()]),
y=np.array([0, np_nan(), 1]),
trendline=mode,
trendline_options=options,
)
Expand All @@ -88,8 +89,8 @@ def test_trendline_enough_values(mode, options):
assert len(fig.data) == 2
assert len(fig.data[1].x) == 2
fig = px.scatter(
x=np.array([0, 1, np.nan, 2]),
y=np.array([1, np.nan, 1, 2]),
x=np.array([0, 1, np_nan(), 2]),
y=np.array([1, np_nan(), 1, 2]),
trendline=mode,
trendline_options=options,
)
Expand All @@ -112,7 +113,7 @@ def test_trendline_enough_values(mode, options):
def test_trendline_nan_values(mode, options):
df = px.data.gapminder().query("continent == 'Oceania'")
start_date = 1970
df["pop"][df["year"] < start_date] = np.nan
df["pop"][df["year"] < start_date] = np_nan()
fig = px.scatter(
df,
x="year",
Expand Down
Loading