From c6911e50d8b48ef49edb0f601ab18e1869ee147b Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Thu, 24 Nov 2022 09:59:33 +0000 Subject: [PATCH] CI: Remove deprecated numpy dtype aliases --- asv_bench/benchmarks/sparse.py | 4 ++-- pandas/core/arrays/sparse/array.py | 4 ++-- pandas/core/interchange/column.py | 2 +- pandas/tests/arrays/sparse/test_indexing.py | 4 ++-- pandas/tests/arrays/sparse/test_reductions.py | 2 +- pandas/tests/arrays/sparse/test_unary.py | 4 ++-- pandas/tests/io/excel/test_writers.py | 9 ++++----- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/asv_bench/benchmarks/sparse.py b/asv_bench/benchmarks/sparse.py index d871f907232f5..10390cb4493cd 100644 --- a/asv_bench/benchmarks/sparse.py +++ b/asv_bench/benchmarks/sparse.py @@ -219,12 +219,12 @@ def setup(self, fill_value): d = 1e-5 arr = make_array(N, d, np.nan, np.float64) self.sp_arr = SparseArray(arr) - b_arr = np.full(shape=N, fill_value=fill_value, dtype=np.bool8) + b_arr = np.full(shape=N, fill_value=fill_value, dtype=np.bool_) fv_inds = np.unique( np.random.randint(low=0, high=N - 1, size=int(N * d), dtype=np.int32) ) b_arr[fv_inds] = True if pd.isna(fill_value) else not fill_value - self.sp_b_arr = SparseArray(b_arr, dtype=np.bool8, fill_value=fill_value) + self.sp_b_arr = SparseArray(b_arr, dtype=np.bool_, fill_value=fill_value) def time_mask(self, fill_value): self.sp_arr[self.sp_b_arr] diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 2462317321a04..7dce02f362b47 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -716,7 +716,7 @@ def isna(self): dtype = SparseDtype(bool, self._null_fill_value) if self._null_fill_value: return type(self)._simple_new(isna(self.sp_values), self.sp_index, dtype) - mask = np.full(len(self), False, dtype=np.bool8) + mask = np.full(len(self), False, dtype=np.bool_) mask[self.sp_index.indices] = isna(self.sp_values) return type(self)(mask, fill_value=False, dtype=dtype) @@ -1003,7 +1003,7 @@ def __getitem__( if not key.fill_value: return self.take(key.sp_index.indices) n = len(self) - mask = np.full(n, True, dtype=np.bool8) + mask = np.full(n, True, dtype=np.bool_) mask[key.sp_index.indices] = False return self.take(np.arange(n)[mask]) else: diff --git a/pandas/core/interchange/column.py b/pandas/core/interchange/column.py index c8675faec440c..d28da1158134e 100644 --- a/pandas/core/interchange/column.py +++ b/pandas/core/interchange/column.py @@ -316,7 +316,7 @@ def _get_validity_buffer(self) -> tuple[PandasBuffer, Any]: valid = invalid == 0 invalid = not valid - mask = np.zeros(shape=(len(buf),), dtype=np.bool8) + mask = np.zeros(shape=(len(buf),), dtype=np.bool_) for i, obj in enumerate(buf): mask[i] = valid if isinstance(obj, str) else invalid diff --git a/pandas/tests/arrays/sparse/test_indexing.py b/pandas/tests/arrays/sparse/test_indexing.py index 63cf44a4f06d3..5acb2167915d2 100644 --- a/pandas/tests/arrays/sparse/test_indexing.py +++ b/pandas/tests/arrays/sparse/test_indexing.py @@ -85,7 +85,7 @@ def test_boolean_slice_empty(self): def test_getitem_bool_sparse_array(self): # GH 23122 - spar_bool = SparseArray([False, True] * 5, dtype=np.bool8, fill_value=True) + spar_bool = SparseArray([False, True] * 5, dtype=np.bool_, fill_value=True) exp = SparseArray([np.nan, 2, np.nan, 5, 6]) tm.assert_sp_array_equal(arr[spar_bool], exp) @@ -95,7 +95,7 @@ def test_getitem_bool_sparse_array(self): tm.assert_sp_array_equal(res, exp) spar_bool = SparseArray( - [False, True, np.nan] * 3, dtype=np.bool8, fill_value=np.nan + [False, True, np.nan] * 3, dtype=np.bool_, fill_value=np.nan ) res = arr[spar_bool] exp = SparseArray([np.nan, 3, 5]) diff --git a/pandas/tests/arrays/sparse/test_reductions.py b/pandas/tests/arrays/sparse/test_reductions.py index 2dd80c52f1419..5d6d65dde69ad 100644 --- a/pandas/tests/arrays/sparse/test_reductions.py +++ b/pandas/tests/arrays/sparse/test_reductions.py @@ -142,7 +142,7 @@ def test_sum_min_count(self, arr, fill_value, min_count, expected): assert result == expected def test_bool_sum_min_count(self): - spar_bool = SparseArray([False, True] * 5, dtype=np.bool8, fill_value=True) + spar_bool = SparseArray([False, True] * 5, dtype=np.bool_, fill_value=True) res = spar_bool.sum(min_count=1) assert res == 5 res = spar_bool.sum(min_count=11) diff --git a/pandas/tests/arrays/sparse/test_unary.py b/pandas/tests/arrays/sparse/test_unary.py index a34c3b0787753..605023a407a06 100644 --- a/pandas/tests/arrays/sparse/test_unary.py +++ b/pandas/tests/arrays/sparse/test_unary.py @@ -59,9 +59,9 @@ def test_abs_operator(self): tm.assert_sp_array_equal(exp, res) def test_invert_operator(self): - arr = SparseArray([False, True, False, True], fill_value=False, dtype=np.bool8) + arr = SparseArray([False, True, False, True], fill_value=False, dtype=np.bool_) exp = SparseArray( - np.invert([False, True, False, True]), fill_value=True, dtype=np.bool8 + np.invert([False, True, False, True]), fill_value=True, dtype=np.bool_ ) res = ~arr tm.assert_sp_array_equal(exp, res) diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 72bcc074ac32e..161587a11fe9e 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -479,15 +479,14 @@ def test_float_types(self, np_type, path): tm.assert_frame_equal(df, recons) - @pytest.mark.parametrize("np_type", [np.bool8, np.bool_]) - def test_bool_types(self, np_type, path): - # Test np.bool8 and np.bool_ values read come back as float. - df = DataFrame([1, 0, True, False], dtype=np_type) + def test_bool_types(self, path): + # Test np.bool_ values read come back as float. + df = DataFrame([1, 0, True, False], dtype=np.bool_) df.to_excel(path, "test1") with ExcelFile(path) as reader: recons = pd.read_excel(reader, sheet_name="test1", index_col=0).astype( - np_type + np.bool_ ) tm.assert_frame_equal(df, recons)