From 99df182e9171e9b9e81811447f37ace05acc9272 Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Sun, 2 Jun 2024 16:43:06 +0200 Subject: [PATCH 1/3] Remove np.nan and np.inf aliases no longer present in numpy2 --- .../tests/test_optional/test_utils/test_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plotly/tests/test_optional/test_utils/test_utils.py b/plotly/tests/test_optional/test_utils/test_utils.py index cf32e1bdff..d7d982e635 100644 --- a/plotly/tests/test_optional/test_utils/test_utils.py +++ b/plotly/tests/test_optional/test_utils/test_utils.py @@ -34,7 +34,7 @@ ## JSON encoding numeric_list = [1, 2, 3] -np_list = np.array([1, 2, 3, np.NaN, np.NAN, np.Inf, dt(2014, 1, 5)]) +np_list = np.array([1, 2, 3, np.nan, np.inf, dt(2014, 1, 5)]) mixed_list = [ 1, "A", @@ -45,7 +45,7 @@ dt_list = [dt(2014, 1, 5), dt(2014, 1, 5, 1, 1, 1), dt(2014, 1, 5, 1, 1, 1, 1)] df = pd.DataFrame( - columns=["col 1"], data=[1, 2, 3, dt(2014, 1, 5), pd.NaT, np.NaN, np.Inf] + columns=["col 1"], data=[1, 2, 3, dt(2014, 1, 5), pd.NaT, np.nan, np.inf] ) rng = pd.date_range("1/1/2011", periods=2, freq="H") @@ -184,7 +184,7 @@ def test_figure_json_encoding(self): assert ( js1 == '{"type": "scatter3d", "x": [1, 2, 3], ' - '"y": [1, 2, 3, null, null, null, "2014-01-05T00:00:00"], ' + '"y": [1, 2, 3, null, null, "2014-01-05T00:00:00"], ' '"z": [1, "A", "2014-01-05T00:00:00", ' '"2014-01-05T01:01:01", "2014-01-05T01:01:01.000001"]}' ) @@ -195,9 +195,9 @@ def test_figure_json_encoding(self): _json.dumps(figure, cls=utils.PlotlyJSONEncoder, sort_keys=True) # Test data wasn't mutated - np_array = np.array([1, 2, 3, np.NaN, np.NAN, np.Inf, dt(2014, 1, 5)]) + np_array = np.array([1, 2, 3, np.nan, np.inf, dt(2014, 1, 5)]) for k in range(len(np_array)): - if k in [3, 4]: + if k == 3: # check NaN assert np.isnan(np_list[k]) and np.isnan(np_array[k]) else: @@ -237,7 +237,7 @@ def test_pandas_json_encoding(self): # Test that data wasn't mutated assert_series_equal( df["col 1"], - pd.Series([1, 2, 3, dt(2014, 1, 5), pd.NaT, np.NaN, np.Inf], name="col 1"), + pd.Series([1, 2, 3, dt(2014, 1, 5), pd.NaT, np.nan, np.inf], name="col 1"), ) j2 = _json.dumps(df.index, cls=utils.PlotlyJSONEncoder) From 23b50d9df805349674e11949459976fb338b3d76 Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Sun, 2 Jun 2024 16:48:34 +0200 Subject: [PATCH 2/3] Avoid putting 255 into int8 due to new numpy 2 type promotion rules --- .../plotly/plotly/tests/test_optional/test_px/test_imshow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotly/tests/test_optional/test_px/test_imshow.py b/plotly/tests/test_optional/test_px/test_imshow.py index c2e863c846..d8f9ad98c7 100644 --- a/plotly/tests/test_optional/test_px/test_imshow.py +++ b/plotly/tests/test_optional/test_px/test_imshow.py @@ -341,7 +341,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 )