From 503fa5579744f873ab6d38628598229c6e46b811 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:15:17 -0400 Subject: [PATCH] [python] Support NumPy 2 (#2934) (#3248) * [python] NumPy 2 experiment [WIP] * fixups from latest CI run Co-authored-by: John Kerl --- apis/python/setup.py | 2 +- apis/python/tests/test_basic_anndata_io.py | 4 ++-- apis/python/tests/test_dataframe.py | 2 +- apis/python/tests/test_regression.py | 4 +--- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apis/python/setup.py b/apis/python/setup.py index cf946f658b..cd9feccd2b 100644 --- a/apis/python/setup.py +++ b/apis/python/setup.py @@ -332,7 +332,7 @@ def run(self): "pyparsing~=3.1.4", "attrs>=22.2", "numba>=0.58.0", - "numpy<2.0", + "numpy", "pandas", "pyarrow", "scanpy>=1.9.2", diff --git a/apis/python/tests/test_basic_anndata_io.py b/apis/python/tests/test_basic_anndata_io.py index b110bdc0e0..5998290263 100644 --- a/apis/python/tests/test_basic_anndata_io.py +++ b/apis/python/tests/test_basic_anndata_io.py @@ -745,7 +745,7 @@ def test_null_obs(conftest_pbmc_small, tmp_path: Path): seed = 42 # Create column of all null values conftest_pbmc_small.obs["empty_categorical_all"] = pd.Categorical( - [np.NaN] * conftest_pbmc_small.n_obs, + [np.nan] * conftest_pbmc_small.n_obs, dtype=pd.CategoricalDtype(categories=[], ordered=False), ) conftest_pbmc_small.obs["empty_extension_all"] = pd.Series( @@ -755,7 +755,7 @@ def test_null_obs(conftest_pbmc_small, tmp_path: Path): rng = np.random.RandomState(seed) conftest_pbmc_small.obs["empty_categorical_partial"] = rng.choice( - (np.NaN, 1.0), conftest_pbmc_small.n_obs, True + (np.nan, 1.0), conftest_pbmc_small.n_obs, True ) conftest_pbmc_small.obs["empty_extension_partial"] = pd.Series( [1] * conftest_pbmc_small.n_obs + [np.nan], dtype=pd.Int64Dtype() diff --git a/apis/python/tests/test_dataframe.py b/apis/python/tests/test_dataframe.py index 30b0861a63..f3297ab3ee 100644 --- a/apis/python/tests/test_dataframe.py +++ b/apis/python/tests/test_dataframe.py @@ -1212,7 +1212,7 @@ def test_extend_enumerations(tmp_path): np.array([0, 1.1, 2.1, 0, 1.1, 2.1], dtype=np.float64), dtype="category" ), "float64_w_non_finite": pd.Series( - np.array([0, 1.1, 2.1, 0, np.Inf, np.NINF], dtype=np.float64), + np.array([0, 1.1, 2.1, 0, np.inf, -np.inf], dtype=np.float64), dtype="category", ), "str_ordered": pd.Series( diff --git a/apis/python/tests/test_regression.py b/apis/python/tests/test_regression.py index 096df8f41f..2092cc70f3 100644 --- a/apis/python/tests/test_regression.py +++ b/apis/python/tests/test_regression.py @@ -10,9 +10,7 @@ def test_nd_dense_non_contiguous_write(tmp_path): """Test regression dected in GitHub Issue #2537""" # Create data. data = ( - np.arange(np.product(24), dtype=np.uint8) - .reshape((4, 3, 2)) - .transpose((2, 0, 1)) + np.arange(np.prod(24), dtype=np.uint8).reshape((4, 3, 2)).transpose((2, 0, 1)) ) coords = tuple(slice(0, dim_len) for dim_len in data.shape) tensor = pa.Tensor.from_numpy(data)