From 11088c9956281dccb04b9c33569d4091ecf08a49 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 7 Jan 2021 15:47:02 +0000 Subject: [PATCH 1/3] DOC: np.bool -> np.bool_ --- asv_bench/benchmarks/groupby.py | 2 +- doc/source/user_guide/basics.rst | 2 +- doc/source/user_guide/cookbook.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/asv_bench/benchmarks/groupby.py b/asv_bench/benchmarks/groupby.py index b4d9db95af163..806cf38ad90b6 100644 --- a/asv_bench/benchmarks/groupby.py +++ b/asv_bench/benchmarks/groupby.py @@ -627,7 +627,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 92905836b763c..66b564838e5e2 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) From 484021cf15f152e6cdc56ec5009ffa038930876d Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 7 Jan 2021 16:15:39 +0000 Subject: [PATCH 2/3] add pre-commit check --- .pre-commit-config.yaml | 5 +++++ pandas/tests/io/excel/test_writers.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 52f923c41cbd4..9416cda5fb2db 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -152,6 +152,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/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index c930acd179330..b12413fbb56c6 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") From f5dd27a714fbbe9091d4c6ae4bf86f679beac2a4 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 7 Jan 2021 16:35:36 +0000 Subject: [PATCH 3/3] Update .pre-commit-config.yaml Co-authored-by: Marco Gorelli --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9416cda5fb2db..9601be40fdebb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -154,7 +154,7 @@ repos: types: [python] - id: np-bool name: Check for use of np.bool instead of np.bool_ - entry: np.bool[^_8] + entry: np\.bool[^_8] language: pygrep types_or: [python, cython, rst] - id: no-os-remove