From d7ce57e7b6280a8b2e285aaa1b1c5128b9b35877 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 7 Jan 2021 18:47:08 +0000 Subject: [PATCH] Backport PR #39019: DOC: np.bool -> np.bool_ --- .pre-commit-config.yaml | 5 +++++ asv_bench/benchmarks/groupby.py | 2 +- doc/source/user_guide/basics.rst | 2 +- doc/source/user_guide/cookbook.rst | 2 +- pandas/tests/io/excel/test_writers.py | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 717334bfe1299..90d65327ea980 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -144,6 +144,11 @@ repos: \#\ type:\s?ignore(?!\[) language: pygrep types: [python] + - id: np-bool + name: Check for use of np.bool instead of np.bool_ + entry: np\.bool[^_8] + language: pygrep + types_or: [python, cython, rst] - id: no-os-remove name: Check code for instances of os.remove entry: os\.remove diff --git a/asv_bench/benchmarks/groupby.py b/asv_bench/benchmarks/groupby.py index 6ce63ff8badca..6cc8e15786795 100644 --- a/asv_bench/benchmarks/groupby.py +++ b/asv_bench/benchmarks/groupby.py @@ -625,7 +625,7 @@ class TransformBools: def setup(self): N = 120000 transition_points = np.sort(np.random.choice(np.arange(N), 1400)) - transitions = np.zeros(N, dtype=np.bool) + transitions = np.zeros(N, dtype=np.bool_) transitions[transition_points] = True self.g = transitions.cumsum() self.df = DataFrame({"signal": np.random.rand(N)}) diff --git a/doc/source/user_guide/basics.rst b/doc/source/user_guide/basics.rst index ffecaa222e1f9..8d38c12252df4 100644 --- a/doc/source/user_guide/basics.rst +++ b/doc/source/user_guide/basics.rst @@ -2229,7 +2229,7 @@ Convert certain columns to a specific dtype by passing a dict to :meth:`~DataFra .. ipython:: python dft1 = pd.DataFrame({"a": [1, 0, 1], "b": [4, 5, 6], "c": [7, 8, 9]}) - dft1 = dft1.astype({"a": np.bool, "c": np.float64}) + dft1 = dft1.astype({"a": np.bool_, "c": np.float64}) dft1 dft1.dtypes diff --git a/doc/source/user_guide/cookbook.rst b/doc/source/user_guide/cookbook.rst index 5a6f56388dee5..77791b4b7e491 100644 --- a/doc/source/user_guide/cookbook.rst +++ b/doc/source/user_guide/cookbook.rst @@ -1406,7 +1406,7 @@ Often it's useful to obtain the lower (or upper) triangular form of a correlatio df = pd.DataFrame(np.random.random(size=(100, 5))) corr_mat = df.corr() - mask = np.tril(np.ones_like(corr_mat, dtype=np.bool), k=-1) + mask = np.tril(np.ones_like(corr_mat, dtype=np.bool_), k=-1) corr_mat.where(mask) diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 197738330efe1..e67769bc774b0 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -492,7 +492,7 @@ def test_float_types(self, np_type, path): @pytest.mark.parametrize("np_type", [np.bool8, np.bool_]) def test_bool_types(self, np_type, path): - # Test np.bool values read come back as float. + # Test np.bool8 and np.bool_ values read come back as float. df = DataFrame([1, 0, True, False], dtype=np_type) df.to_excel(path, "test1")