From abab690d6271112872aed3822aa6ac55ca784a5b Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 3 Mar 2023 15:10:11 +0530 Subject: [PATCH 01/37] added deprecation warning --- pandas/core/generic.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 821e41db6b065..8c5e7e46521e6 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1504,6 +1504,14 @@ def bool(self) -> bool_t: "bool cannot act on a non-boolean single element " f"{type(self).__name__}" ) + else: + warnings.warn( + f"Passing a slice to {type(self).__name__}.take is deprecated " + "and will raise in a future version. Use `obj[slicer]` or pass " + "a sequence of integers instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) self.__nonzero__() # for mypy (__nonzero__ raises) From 79981ec66c75d6e7cc6b463072f31a64aafefe78 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 3 Mar 2023 17:40:34 +0530 Subject: [PATCH 02/37] Added test and corrected the warning --- pandas/core/generic.py | 16 +++++++--------- pandas/tests/generic/test_generic.py | 9 +++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8c5e7e46521e6..0b72cde10662b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1496,6 +1496,12 @@ def bool(self) -> bool_t: >>> pd.DataFrame({'col': [False]}).bool() False """ + warnings.warn( + "NDFrame.bool is deprecated" + "and will removed in a future version.", + FutureWarning, + stacklevel=find_stack_level(), + ) v = self.squeeze() if isinstance(v, (bool, np.bool_)): return bool(v) @@ -1503,15 +1509,7 @@ def bool(self) -> bool_t: raise ValueError( "bool cannot act on a non-boolean single element " f"{type(self).__name__}" - ) - else: - warnings.warn( - f"Passing a slice to {type(self).__name__}.take is deprecated " - "and will raise in a future version. Use `obj[slicer]` or pass " - "a sequence of integers instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) + ) self.__nonzero__() # for mypy (__nonzero__ raises) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 54d08b577a47a..88dd6079f59a0 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -4,6 +4,7 @@ ) import numpy as np +import pandas as pd import pytest from pandas.core.dtypes.common import is_scalar @@ -441,3 +442,11 @@ def test_flags_identity(self, frame_or_series): assert obj.flags is obj.flags obj2 = obj.copy() assert obj2.flags is not obj.flags + + def test_bool_dep(self) -> None: + msg = ( + "NDFRame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + pd.DataFrame({'col': [False]}).bool() From ed09b05bca55dbd5dc92fce8f51ce6d231c9809e Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 3 Mar 2023 17:42:48 +0530 Subject: [PATCH 03/37] Update generic.py --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0b72cde10662b..a327edbd66ea2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1509,7 +1509,7 @@ def bool(self) -> bool_t: raise ValueError( "bool cannot act on a non-boolean single element " f"{type(self).__name__}" - ) + ) self.__nonzero__() # for mypy (__nonzero__ raises) From 9972bc6fd8ca623ba415a583e680ace305fc8f41 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 3 Mar 2023 18:10:45 +0530 Subject: [PATCH 04/37] Update generic.py --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a327edbd66ea2..b2e1602f0b60b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1496,9 +1496,9 @@ def bool(self) -> bool_t: >>> pd.DataFrame({'col': [False]}).bool() False """ + warnings.warn( - "NDFrame.bool is deprecated" - "and will removed in a future version.", + "NDFrame.bool is deprecated and will removed in a future version.", FutureWarning, stacklevel=find_stack_level(), ) From a0dd906e1837065acd911f89a6bf07c0c1885726 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 3 Mar 2023 18:29:36 +0530 Subject: [PATCH 05/37] Update test_generic.py --- pandas/tests/generic/test_generic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 88dd6079f59a0..9388e951e4218 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -4,11 +4,11 @@ ) import numpy as np -import pandas as pd import pytest from pandas.core.dtypes.common import is_scalar +import pandas as pd from pandas import ( DataFrame, Series, @@ -445,8 +445,8 @@ def test_flags_identity(self, frame_or_series): def test_bool_dep(self) -> None: msg = ( - "NDFRame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version" - ) + "NDFRame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version" + ) with tm.assert_produces_warning(FutureWarning, match=msg): - pd.DataFrame({'col': [False]}).bool() + pd.DataFrame({"col": [False]}).bool() From b0c69d6493147cb96b4dc4072d28ee9df2204dc8 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 4 Mar 2023 20:33:25 +0530 Subject: [PATCH 06/37] removed examples from doc --- doc/source/user_guide/basics.rst | 10 ---------- doc/source/user_guide/gotchas.rst | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/doc/source/user_guide/basics.rst b/doc/source/user_guide/basics.rst index 5c2f2410e688c..16a85ccc74b43 100644 --- a/doc/source/user_guide/basics.rst +++ b/doc/source/user_guide/basics.rst @@ -329,16 +329,6 @@ You can test if a pandas object is empty, via the :attr:`~DataFrame.empty` prope df.empty pd.DataFrame(columns=list("ABC")).empty -To evaluate single-element pandas objects in a boolean context, use the method -:meth:`~DataFrame.bool`: - -.. ipython:: python - - pd.Series([True]).bool() - pd.Series([False]).bool() - pd.DataFrame([[True]]).bool() - pd.DataFrame([[False]]).bool() - .. warning:: You might be tempted to do the following: diff --git a/doc/source/user_guide/gotchas.rst b/doc/source/user_guide/gotchas.rst index adb40e166eab4..47f1b74c0b894 100644 --- a/doc/source/user_guide/gotchas.rst +++ b/doc/source/user_guide/gotchas.rst @@ -121,16 +121,6 @@ Below is how to check if any of the values are ``True``: if pd.Series([False, True, False]).any(): print("I am any") -To evaluate single-element pandas objects in a boolean context, use the method -:meth:`~DataFrame.bool`: - -.. ipython:: python - - pd.Series([True]).bool() - pd.Series([False]).bool() - pd.DataFrame([[True]]).bool() - pd.DataFrame([[False]]).bool() - Bitwise boolean ~~~~~~~~~~~~~~~ From e5ccfa497fd0b5b97137abe9e373dd94038747f4 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 4 Mar 2023 20:38:42 +0530 Subject: [PATCH 07/37] Update test_generic.py --- pandas/tests/generic/test_generic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 9388e951e4218..0e2c996538d7e 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -8,7 +8,6 @@ from pandas.core.dtypes.common import is_scalar -import pandas as pd from pandas import ( DataFrame, Series, @@ -449,4 +448,4 @@ def test_bool_dep(self) -> None: "and cases that relied on it will raise in a future version" ) with tm.assert_produces_warning(FutureWarning, match=msg): - pd.DataFrame({"col": [False]}).bool() + DataFrame({"col": [False]}).bool() From 748a8e0906b98229620e8b4255f92a763bfabceb Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 10 Mar 2023 19:28:37 +0530 Subject: [PATCH 08/37] added warning in 'ignored_doctest_warnings' --- pandas/conftest.py | 4 ++++ pandas/tests/generic/test_generic.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 05f473059758c..8c48cb896860a 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -137,6 +137,10 @@ def pytest_collection_modifyitems(items, config) -> None: ignored_doctest_warnings = [ # Docstring divides by zero to show behavior difference ("missing.mask_zero_div_zero", "divide by zero encountered"), + ( + "pandas.core.generic.py", + "NDFrame.bool is deprecated and will removed in a future version", + ), ] for item in items: diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 0e2c996538d7e..0cebc542f4a58 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -444,7 +444,7 @@ def test_flags_identity(self, frame_or_series): def test_bool_dep(self) -> None: msg = ( - "NDFRame.bool is now deprecated and will be removed in future releases " + "NDFrame.bool is now deprecated and will be removed in future releases " "and cases that relied on it will raise in a future version" ) with tm.assert_produces_warning(FutureWarning, match=msg): From 13cf306039ccb581af868756d80841e6e1abb837 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 10 Mar 2023 20:00:31 +0530 Subject: [PATCH 09/37] updated path --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 8c48cb896860a..3c888316be28b 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -138,7 +138,7 @@ def pytest_collection_modifyitems(items, config) -> None: # Docstring divides by zero to show behavior difference ("missing.mask_zero_div_zero", "divide by zero encountered"), ( - "pandas.core.generic.py", + "pandas.core.generic.NDFrame.bool", "NDFrame.bool is deprecated and will removed in a future version", ), ] From 70d26acec85c25c6a7e858021af0a1a6aa25cb42 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 10 Mar 2023 21:10:55 +0530 Subject: [PATCH 10/37] updated other tests with bool --- pandas/core/generic.py | 3 +- pandas/tests/generic/test_frame.py | 29 ++++++---- pandas/tests/generic/test_series.py | 58 +++++++++++++------ pandas/tests/window/test_timeseries_window.py | 19 +++--- 4 files changed, 70 insertions(+), 39 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e82593b506258..cd830e462fdc9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1503,7 +1503,8 @@ def bool(self) -> bool_t: """ warnings.warn( - "NDFrame.bool is deprecated and will removed in a future version.", + "NDFrame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/tests/generic/test_frame.py b/pandas/tests/generic/test_frame.py index 8a1e0f0923531..b28a4896f249c 100644 --- a/pandas/tests/generic/test_frame.py +++ b/pandas/tests/generic/test_frame.py @@ -47,18 +47,23 @@ def test_set_axis_name_mi(self, func): def test_nonzero_single_element(self): # allow single item via bool method - df = DataFrame([[True]]) - assert df.bool() - - df = DataFrame([[False]]) - assert not df.bool() - - df = DataFrame([[False, False]]) - msg = "The truth value of a DataFrame is ambiguous" - with pytest.raises(ValueError, match=msg): - df.bool() - with pytest.raises(ValueError, match=msg): - bool(df) + msg = ( + "NDFrame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + df = DataFrame([[True]]) + assert df.bool() + + df = DataFrame([[False]]) + assert not df.bool() + + df = DataFrame([[False, False]]) + msg = "The truth value of a DataFrame is ambiguous" + with pytest.raises(ValueError, match=msg): + df.bool() + with pytest.raises(ValueError, match=msg): + bool(df) def test_metadata_propagation_indiv_groupby(self): # groupby diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index 5098897f057a5..157d5aa55521c 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -41,8 +41,13 @@ def test_get_bool_data_preserve_dtype(self): def test_nonzero_single_element(self): # allow single item via bool method - ser = Series([True]) - assert ser.bool() + msg = ( + "NDFrame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + ser = Series([True]) + assert ser.bool() ser = Series([False]) assert not ser.bool() @@ -58,35 +63,50 @@ def test_nonzero_single_element_raise_1(self, data): @pytest.mark.parametrize("data", [np.nan, pd.NaT]) def test_nonzero_single_element_raise_2(self, data): - series = Series([data]) + msg = ( + "NDFrame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + series = Series([data]) - msg = "bool cannot act on a non-boolean single element Series" - with pytest.raises(ValueError, match=msg): - series.bool() + msg = "bool cannot act on a non-boolean single element Series" + with pytest.raises(ValueError, match=msg): + series.bool() @pytest.mark.parametrize("data", [(True, True), (False, False)]) def test_nonzero_multiple_element_raise(self, data): # multiple bool are still an error - series = Series([data]) + msg = ( + "NDFrame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + series = Series([data]) - msg = "The truth value of a Series is ambiguous" - with pytest.raises(ValueError, match=msg): - bool(series) - with pytest.raises(ValueError, match=msg): - series.bool() + msg = "The truth value of a Series is ambiguous" + with pytest.raises(ValueError, match=msg): + bool(series) + with pytest.raises(ValueError, match=msg): + series.bool() @pytest.mark.parametrize("data", [1, 0, "a", 0.0]) def test_nonbool_single_element_raise(self, data): # single non-bool are an error - series = Series([data]) + msg = ( + "NDFrame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + series = Series([data]) - msg = "The truth value of a Series is ambiguous" - with pytest.raises(ValueError, match=msg): - bool(series) + msg = "The truth value of a Series is ambiguous" + with pytest.raises(ValueError, match=msg): + bool(series) - msg = "bool cannot act on a non-boolean single element Series" - with pytest.raises(ValueError, match=msg): - series.bool() + msg = "bool cannot act on a non-boolean single element Series" + with pytest.raises(ValueError, match=msg): + series.bool() def test_metadata_propagation_indiv_resample(self): # resample diff --git a/pandas/tests/window/test_timeseries_window.py b/pandas/tests/window/test_timeseries_window.py index 0de4b863183df..33f80f6eb70cb 100644 --- a/pandas/tests/window/test_timeseries_window.py +++ b/pandas/tests/window/test_timeseries_window.py @@ -506,13 +506,18 @@ def test_perf_min(self): dfp = DataFrame( {"B": np.random.randn(N)}, index=date_range("20130101", periods=N, freq="s") ) - expected = dfp.rolling(2, min_periods=1).min() - result = dfp.rolling("2s").min() - assert ((result - expected) < 0.01).all().bool() - - expected = dfp.rolling(200, min_periods=1).min() - result = dfp.rolling("200s").min() - assert ((result - expected) < 0.01).all().bool() + msg = ( + "NDFrame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + expected = dfp.rolling(2, min_periods=1).min() + result = dfp.rolling("2s").min() + assert ((result - expected) < 0.01).all().bool() + + expected = dfp.rolling(200, min_periods=1).min() + result = dfp.rolling("200s").min() + assert ((result - expected) < 0.01).all().bool() def test_ragged_max(self, ragged): df = ragged From c6bd26ffe777770bffcfffdacb5c20a08e3875b2 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 10 Mar 2023 21:28:29 +0530 Subject: [PATCH 11/37] Update conftest.py --- pandas/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 3c888316be28b..3769ca846e877 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -139,7 +139,8 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - "NDFrame.bool is deprecated and will removed in a future version", + "NDFrame.bool is now deprecated and will be removed in future releases " + "and cases that relied on it will raise in a future version", ), ] From bcb5bb98fafcd0be04c3d6e53564495f9bbc4a2d Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 10 Mar 2023 22:16:54 +0530 Subject: [PATCH 12/37] Update test_series.py --- pandas/tests/generic/test_series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index 157d5aa55521c..cca0b0e7b8cbf 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -49,8 +49,8 @@ def test_nonzero_single_element(self): ser = Series([True]) assert ser.bool() - ser = Series([False]) - assert not ser.bool() + ser = Series([False]) + assert not ser.bool() @pytest.mark.parametrize("data", [np.nan, pd.NaT, True, False]) def test_nonzero_single_element_raise_1(self, data): From dd2b1e14b513d2b2968e156637378dd6c9534e02 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 13:45:18 +0530 Subject: [PATCH 13/37] required changes done --- pandas/conftest.py | 4 +-- pandas/core/generic.py | 4 +-- pandas/tests/generic/test_frame.py | 12 +++---- pandas/tests/generic/test_generic.py | 4 +-- pandas/tests/generic/test_series.py | 34 +++++++++---------- pandas/tests/window/test_timeseries_window.py | 20 +++++------ 6 files changed, 36 insertions(+), 42 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 3769ca846e877..40343a056dff9 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -139,8 +139,8 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - "NDFrame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version", + "NDFrame.bool is now deprecated and will be removed in future version of pandas " + "and cases that relied on it will raise a future warning", ), ] diff --git a/pandas/core/generic.py b/pandas/core/generic.py index cd830e462fdc9..6f114d658d4f8 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1503,8 +1503,8 @@ def bool(self) -> bool_t: """ warnings.warn( - "NDFrame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version", + "type(self).__name__ is now deprecated and will be removed in future " + "version of pandas and cases that relied on it will raise a future warning", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/tests/generic/test_frame.py b/pandas/tests/generic/test_frame.py index b28a4896f249c..f8c7b390de7ca 100644 --- a/pandas/tests/generic/test_frame.py +++ b/pandas/tests/generic/test_frame.py @@ -48,15 +48,15 @@ def test_set_axis_name_mi(self, func): def test_nonzero_single_element(self): # allow single item via bool method msg = ( - "NDFrame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version" + "NDFrame.bool is now deprecated and will be removed in future version of pandas " + "and cases that relied on it will raise a future warning" ) - with tm.assert_produces_warning(FutureWarning, match=msg): - df = DataFrame([[True]]) + df = DataFrame([[True]]) + df1 = DataFrame([[False]]) + while tm.assert_produces_warning(FutureWarning, match=msg): assert df.bool() - df = DataFrame([[False]]) - assert not df.bool() + assert not df1.bool() df = DataFrame([[False, False]]) msg = "The truth value of a DataFrame is ambiguous" diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 0cebc542f4a58..f7915bc6e3467 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -444,8 +444,8 @@ def test_flags_identity(self, frame_or_series): def test_bool_dep(self) -> None: msg = ( - "NDFrame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version" + "NDFrame.bool is now deprecated and will be removed in future version of pandas " + "and cases that relied on it will raise a future warning" ) with tm.assert_produces_warning(FutureWarning, match=msg): DataFrame({"col": [False]}).bool() diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index cca0b0e7b8cbf..d5b9155e5c6c8 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -42,15 +42,15 @@ def test_get_bool_data_preserve_dtype(self): def test_nonzero_single_element(self): # allow single item via bool method msg = ( - "NDFrame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version" + "NDFrame.bool is now deprecated and will be removed in future version of pandas " + "and cases that relied on it will raise a future warning" ) - with tm.assert_produces_warning(FutureWarning, match=msg): - ser = Series([True]) + ser = Series([True]) + ser1 = Series([False]) + while tm.assert_produces_warning(FutureWarning, match=msg): assert ser.bool() - ser = Series([False]) - assert not ser.bool() + assert not ser1.bool() @pytest.mark.parametrize("data", [np.nan, pd.NaT, True, False]) def test_nonzero_single_element_raise_1(self, data): @@ -64,12 +64,11 @@ def test_nonzero_single_element_raise_1(self, data): @pytest.mark.parametrize("data", [np.nan, pd.NaT]) def test_nonzero_single_element_raise_2(self, data): msg = ( - "NDFrame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version" + "NDFrame.bool is now deprecated and will be removed in future version of pandas " + "and cases that relied on it will raise a future warning" ) - with tm.assert_produces_warning(FutureWarning, match=msg): - series = Series([data]) - + series = Series([data]) + while tm.assert_produces_warning(FutureWarning, match=msg): msg = "bool cannot act on a non-boolean single element Series" with pytest.raises(ValueError, match=msg): series.bool() @@ -78,12 +77,11 @@ def test_nonzero_single_element_raise_2(self, data): def test_nonzero_multiple_element_raise(self, data): # multiple bool are still an error msg = ( - "NDFrame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version" + "NDFrame.bool is now deprecated and will be removed in future version of pandas " + "and cases that relied on it will raise a future warning" ) - with tm.assert_produces_warning(FutureWarning, match=msg): - series = Series([data]) - + series = Series([data]) + while tm.assert_produces_warning(FutureWarning, match=msg): msg = "The truth value of a Series is ambiguous" with pytest.raises(ValueError, match=msg): bool(series) @@ -94,8 +92,8 @@ def test_nonzero_multiple_element_raise(self, data): def test_nonbool_single_element_raise(self, data): # single non-bool are an error msg = ( - "NDFrame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version" + "NDFrame.bool is now deprecated and will be removed in future version of pandas " + "and cases that relied on it will raise a future warning" ) with tm.assert_produces_warning(FutureWarning, match=msg): series = Series([data]) diff --git a/pandas/tests/window/test_timeseries_window.py b/pandas/tests/window/test_timeseries_window.py index 33f80f6eb70cb..b86e775ce5db8 100644 --- a/pandas/tests/window/test_timeseries_window.py +++ b/pandas/tests/window/test_timeseries_window.py @@ -506,18 +506,14 @@ def test_perf_min(self): dfp = DataFrame( {"B": np.random.randn(N)}, index=date_range("20130101", periods=N, freq="s") ) - msg = ( - "NDFrame.bool is now deprecated and will be removed in future releases " - "and cases that relied on it will raise in a future version" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - expected = dfp.rolling(2, min_periods=1).min() - result = dfp.rolling("2s").min() - assert ((result - expected) < 0.01).all().bool() - - expected = dfp.rolling(200, min_periods=1).min() - result = dfp.rolling("200s").min() - assert ((result - expected) < 0.01).all().bool() + + expected = dfp.rolling(2, min_periods=1).min() + result = dfp.rolling("2s").min() + assert ((result - expected) < 0.01).all() == True + + expected = dfp.rolling(200, min_periods=1).min() + result = dfp.rolling("200s").min() + assert ((result - expected) < 0.01).all() == True def test_ragged_max(self, ragged): df = ragged From ea3fee4d562c4b4f53efb948bc3c2c48ba9177ae Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 14:00:43 +0530 Subject: [PATCH 14/37] minimal changes --- pandas/conftest.py | 4 ++-- pandas/core/generic.py | 2 +- pandas/tests/generic/test_frame.py | 4 ++-- pandas/tests/generic/test_generic.py | 4 ++-- pandas/tests/generic/test_series.py | 16 ++++++++-------- pandas/tests/window/test_timeseries_window.py | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 40343a056dff9..53155b9055562 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -139,8 +139,8 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - "NDFrame.bool is now deprecated and will be removed in future version of pandas " - "and cases that relied on it will raise a future warning", + "NDFrame.bool is now deprecated and will be removed in future version " + "of pandas and cases that relied on it will raise a future warning", ), ] diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6f114d658d4f8..9997382aa83cc 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1503,7 +1503,7 @@ def bool(self) -> bool_t: """ warnings.warn( - "type(self).__name__ is now deprecated and will be removed in future " + "{type(self).__name__}.bool is now deprecated and will be removed in future " "version of pandas and cases that relied on it will raise a future warning", FutureWarning, stacklevel=find_stack_level(), diff --git a/pandas/tests/generic/test_frame.py b/pandas/tests/generic/test_frame.py index f8c7b390de7ca..8c06565b79034 100644 --- a/pandas/tests/generic/test_frame.py +++ b/pandas/tests/generic/test_frame.py @@ -48,8 +48,8 @@ def test_set_axis_name_mi(self, func): def test_nonzero_single_element(self): # allow single item via bool method msg = ( - "NDFrame.bool is now deprecated and will be removed in future version of pandas " - "and cases that relied on it will raise a future warning" + "NDFrame.bool is now deprecated and will be removed in future version " + "of pandas and cases that relied on it will raise a future warning" ) df = DataFrame([[True]]) df1 = DataFrame([[False]]) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index f7915bc6e3467..1cf7b4ded08ac 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -444,8 +444,8 @@ def test_flags_identity(self, frame_or_series): def test_bool_dep(self) -> None: msg = ( - "NDFrame.bool is now deprecated and will be removed in future version of pandas " - "and cases that relied on it will raise a future warning" + "NDFrame.bool is now deprecated and will be removed in future version " + "of pandas and cases that relied on it will raise a future warning" ) with tm.assert_produces_warning(FutureWarning, match=msg): DataFrame({"col": [False]}).bool() diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index d5b9155e5c6c8..699306ae243da 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -42,8 +42,8 @@ def test_get_bool_data_preserve_dtype(self): def test_nonzero_single_element(self): # allow single item via bool method msg = ( - "NDFrame.bool is now deprecated and will be removed in future version of pandas " - "and cases that relied on it will raise a future warning" + "NDFrame.bool is now deprecated and will be removed in future version " + "of pandas and cases that relied on it will raise a future warning" ) ser = Series([True]) ser1 = Series([False]) @@ -64,8 +64,8 @@ def test_nonzero_single_element_raise_1(self, data): @pytest.mark.parametrize("data", [np.nan, pd.NaT]) def test_nonzero_single_element_raise_2(self, data): msg = ( - "NDFrame.bool is now deprecated and will be removed in future version of pandas " - "and cases that relied on it will raise a future warning" + "NDFrame.bool is now deprecated and will be removed in future version " + "of pandas and cases that relied on it will raise a future warning" ) series = Series([data]) while tm.assert_produces_warning(FutureWarning, match=msg): @@ -77,8 +77,8 @@ def test_nonzero_single_element_raise_2(self, data): def test_nonzero_multiple_element_raise(self, data): # multiple bool are still an error msg = ( - "NDFrame.bool is now deprecated and will be removed in future version of pandas " - "and cases that relied on it will raise a future warning" + "NDFrame.bool is now deprecated and will be removed in future version " + "of pandas and cases that relied on it will raise a future warning" ) series = Series([data]) while tm.assert_produces_warning(FutureWarning, match=msg): @@ -92,8 +92,8 @@ def test_nonzero_multiple_element_raise(self, data): def test_nonbool_single_element_raise(self, data): # single non-bool are an error msg = ( - "NDFrame.bool is now deprecated and will be removed in future version of pandas " - "and cases that relied on it will raise a future warning" + "NDFrame.bool is now deprecated and will be removed in future version " + "of pandas and cases that relied on it will raise a future warning" ) with tm.assert_produces_warning(FutureWarning, match=msg): series = Series([data]) diff --git a/pandas/tests/window/test_timeseries_window.py b/pandas/tests/window/test_timeseries_window.py index b86e775ce5db8..afa092fb755dc 100644 --- a/pandas/tests/window/test_timeseries_window.py +++ b/pandas/tests/window/test_timeseries_window.py @@ -509,11 +509,11 @@ def test_perf_min(self): expected = dfp.rolling(2, min_periods=1).min() result = dfp.rolling("2s").min() - assert ((result - expected) < 0.01).all() == True + assert ((result - expected) < 0.01).all() is True expected = dfp.rolling(200, min_periods=1).min() result = dfp.rolling("200s").min() - assert ((result - expected) < 0.01).all() == True + assert ((result - expected) < 0.01).all() is True def test_ragged_max(self, ragged): df = ragged From a84aa47a17f7d40789f759981f14fe44d72ea012 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 14:03:22 +0530 Subject: [PATCH 15/37] Update generic.py --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 9997382aa83cc..6a0e54e5d8399 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1503,8 +1503,8 @@ def bool(self) -> bool_t: """ warnings.warn( - "{type(self).__name__}.bool is now deprecated and will be removed in future " - "version of pandas and cases that relied on it will raise a future warning", + "{type(self).__name__}.bool is now deprecated and will be removed in future" + " version of pandas and cases that relied on it will raise a future warning", FutureWarning, stacklevel=find_stack_level(), ) From 98085403d832c95ad408f7b8adc16e43ba5c068e Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 14:05:50 +0530 Subject: [PATCH 16/37] Update generic.py --- pandas/core/generic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6a0e54e5d8399..5a52965732539 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1503,8 +1503,9 @@ def bool(self) -> bool_t: """ warnings.warn( - "{type(self).__name__}.bool is now deprecated and will be removed in future" - " version of pandas and cases that relied on it will raise a future warning", + "{type(self).__name__}.bool is now deprecated and will be removed " + "in future version of pandas and cases that relied on it will raise " + "a future warning", FutureWarning, stacklevel=find_stack_level(), ) From a15a72397b359cdef1d0b433943a71b777e63357 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 14:18:49 +0530 Subject: [PATCH 17/37] Update conftest.py --- pandas/conftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 53155b9055562..694188db2ceff 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -139,8 +139,9 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - "NDFrame.bool is now deprecated and will be removed in future version " - "of pandas and cases that relied on it will raise a future warning", + "{type(self).__name__}.bool is now deprecated and will be removed " + "in future version of pandas and cases that relied on it will raise " + "a future warning", ), ] From ad7c16deaba02bd652dc930e6bc0586bb42f040b Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 14:52:36 +0530 Subject: [PATCH 18/37] updated the warning --- pandas/conftest.py | 2 +- pandas/core/generic.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 694188db2ceff..e815aaa96dc59 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -139,7 +139,7 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - "{type(self).__name__}.bool is now deprecated and will be removed " + "NDFrame.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning", ), diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5a52965732539..651e3635b6955 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1503,7 +1503,7 @@ def bool(self) -> bool_t: """ warnings.warn( - "{type(self).__name__}.bool is now deprecated and will be removed " + f"{type(self).__name__}.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning", FutureWarning, From 11fe948726c4aedbb30173d787a96ac76273fb3b Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 15:35:45 +0530 Subject: [PATCH 19/37] warning message changed --- pandas/conftest.py | 3 +- pandas/tests/generic/test_frame.py | 17 +++++---- pandas/tests/generic/test_generic.py | 6 ++-- pandas/tests/generic/test_series.py | 54 +++++++++++++++------------- 4 files changed, 46 insertions(+), 34 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index e815aaa96dc59..126c38d9a873f 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -34,6 +34,7 @@ Callable, Hashable, Iterator, + Self, ) from dateutil.tz import ( @@ -139,7 +140,7 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - "NDFrame.bool is now deprecated and will be removed " + f"{type(Self).__name__}.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning", ), diff --git a/pandas/tests/generic/test_frame.py b/pandas/tests/generic/test_frame.py index 8c06565b79034..74b616650b77e 100644 --- a/pandas/tests/generic/test_frame.py +++ b/pandas/tests/generic/test_frame.py @@ -1,5 +1,6 @@ from copy import deepcopy from operator import methodcaller +from typing import Self import numpy as np import pytest @@ -48,22 +49,26 @@ def test_set_axis_name_mi(self, func): def test_nonzero_single_element(self): # allow single item via bool method msg = ( - "NDFrame.bool is now deprecated and will be removed in future version " - "of pandas and cases that relied on it will raise a future warning" + f"{type(Self).__name__}.bool is now deprecated and will be removed " + "in future version of pandas and cases that relied on it will raise " + "a future warning" ) df = DataFrame([[True]]) df1 = DataFrame([[False]]) while tm.assert_produces_warning(FutureWarning, match=msg): assert df.bool() + with tm.assert_produces_warning(FutureWarning, match=msg): assert not df1.bool() - df = DataFrame([[False, False]]) - msg = "The truth value of a DataFrame is ambiguous" + df = DataFrame([[False, False]]) + msg = "The truth value of a DataFrame is ambiguous" + with pytest.raises(ValueError, match=msg): + bool(df) + + with tm.assert_produces_warning(FutureWarning, match=msg): with pytest.raises(ValueError, match=msg): df.bool() - with pytest.raises(ValueError, match=msg): - bool(df) def test_metadata_propagation_indiv_groupby(self): # groupby diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 1cf7b4ded08ac..bc0dd8870c2d9 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -2,6 +2,7 @@ copy, deepcopy, ) +from typing import Self import numpy as np import pytest @@ -444,8 +445,9 @@ def test_flags_identity(self, frame_or_series): def test_bool_dep(self) -> None: msg = ( - "NDFrame.bool is now deprecated and will be removed in future version " - "of pandas and cases that relied on it will raise a future warning" + f"{type(Self).__name__}.bool is now deprecated and will be removed " + "in future version of pandas and cases that relied on it will raise " + "a future warning" ) with tm.assert_produces_warning(FutureWarning, match=msg): DataFrame({"col": [False]}).bool() diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index 699306ae243da..910a5fb3a3fc8 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -1,4 +1,5 @@ from operator import methodcaller +from typing import Self import numpy as np import pytest @@ -42,14 +43,15 @@ def test_get_bool_data_preserve_dtype(self): def test_nonzero_single_element(self): # allow single item via bool method msg = ( - "NDFrame.bool is now deprecated and will be removed in future version " - "of pandas and cases that relied on it will raise a future warning" + f"{type(Self).__name__}.bool is now deprecated and will be removed " + "in future version of pandas and cases that relied on it will raise " + "a future warning" ) ser = Series([True]) ser1 = Series([False]) - while tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg): assert ser.bool() - + with tm.assert_produces_warning(FutureWarning, match=msg): assert not ser1.bool() @pytest.mark.parametrize("data", [np.nan, pd.NaT, True, False]) @@ -64,46 +66,48 @@ def test_nonzero_single_element_raise_1(self, data): @pytest.mark.parametrize("data", [np.nan, pd.NaT]) def test_nonzero_single_element_raise_2(self, data): msg = ( - "NDFrame.bool is now deprecated and will be removed in future version " - "of pandas and cases that relied on it will raise a future warning" + f"{type(Self).__name__}.bool is now deprecated and will be removed " + "in future version of pandas and cases that relied on it will raise " + "a future warning" ) + msg1 = "bool cannot act on a non-boolean single element Series" series = Series([data]) - while tm.assert_produces_warning(FutureWarning, match=msg): - msg = "bool cannot act on a non-boolean single element Series" - with pytest.raises(ValueError, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg): + with pytest.raises(ValueError, match=msg1): series.bool() @pytest.mark.parametrize("data", [(True, True), (False, False)]) def test_nonzero_multiple_element_raise(self, data): # multiple bool are still an error msg = ( - "NDFrame.bool is now deprecated and will be removed in future version " - "of pandas and cases that relied on it will raise a future warning" + f"{type(Self).__name__}.bool is now deprecated and will be removed " + "in future version of pandas and cases that relied on it will raise " + "a future warning" ) + msg1 = "The truth value of a Series is ambiguous" series = Series([data]) - while tm.assert_produces_warning(FutureWarning, match=msg): - msg = "The truth value of a Series is ambiguous" - with pytest.raises(ValueError, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg): + with pytest.raises(ValueError, match=msg1): bool(series) - with pytest.raises(ValueError, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg): + with pytest.raises(ValueError, match=msg1): series.bool() @pytest.mark.parametrize("data", [1, 0, "a", 0.0]) def test_nonbool_single_element_raise(self, data): # single non-bool are an error msg = ( - "NDFrame.bool is now deprecated and will be removed in future version " - "of pandas and cases that relied on it will raise a future warning" + f"{type(Self).__name__}.bool is now deprecated and will be removed " + "in future version of pandas and cases that relied on it will raise " + "a future warning" ) - with tm.assert_produces_warning(FutureWarning, match=msg): - series = Series([data]) - - msg = "The truth value of a Series is ambiguous" - with pytest.raises(ValueError, match=msg): + msg1 = "The truth value of a Series is ambiguous" + msg2 = "bool cannot act on a non-boolean single element Series" + series = Series([data]) + with pytest.raises(ValueError, match=msg1): bool(series) - - msg = "bool cannot act on a non-boolean single element Series" - with pytest.raises(ValueError, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg): + with pytest.raises(ValueError, match=msg2): series.bool() def test_metadata_propagation_indiv_resample(self): From 559520cecb019e2b1c68bd12d312b8091ccdc479 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 15:45:36 +0530 Subject: [PATCH 20/37] Update test_series.py --- pandas/tests/generic/test_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index 910a5fb3a3fc8..6d4b9c2d3e70a 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -105,7 +105,7 @@ def test_nonbool_single_element_raise(self, data): msg2 = "bool cannot act on a non-boolean single element Series" series = Series([data]) with pytest.raises(ValueError, match=msg1): - bool(series) + bool(series) with tm.assert_produces_warning(FutureWarning, match=msg): with pytest.raises(ValueError, match=msg2): series.bool() From 96224495738007830000dabfce1c1cb3b5e547dd Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 15:57:48 +0530 Subject: [PATCH 21/37] update --- pandas/conftest.py | 3 +-- pandas/tests/generic/test_frame.py | 3 +-- pandas/tests/generic/test_generic.py | 3 +-- pandas/tests/generic/test_series.py | 14 ++++++-------- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 126c38d9a873f..e815aaa96dc59 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -34,7 +34,6 @@ Callable, Hashable, Iterator, - Self, ) from dateutil.tz import ( @@ -140,7 +139,7 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - f"{type(Self).__name__}.bool is now deprecated and will be removed " + "NDFrame.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning", ), diff --git a/pandas/tests/generic/test_frame.py b/pandas/tests/generic/test_frame.py index 74b616650b77e..29561cf45cccd 100644 --- a/pandas/tests/generic/test_frame.py +++ b/pandas/tests/generic/test_frame.py @@ -1,6 +1,5 @@ from copy import deepcopy from operator import methodcaller -from typing import Self import numpy as np import pytest @@ -49,7 +48,7 @@ def test_set_axis_name_mi(self, func): def test_nonzero_single_element(self): # allow single item via bool method msg = ( - f"{type(Self).__name__}.bool is now deprecated and will be removed " + "DataFrame.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning" ) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index bc0dd8870c2d9..549980875bd23 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -2,7 +2,6 @@ copy, deepcopy, ) -from typing import Self import numpy as np import pytest @@ -445,7 +444,7 @@ def test_flags_identity(self, frame_or_series): def test_bool_dep(self) -> None: msg = ( - f"{type(Self).__name__}.bool is now deprecated and will be removed " + "DataFrame.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning" ) diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index 6d4b9c2d3e70a..c4941d27e393c 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -1,5 +1,4 @@ from operator import methodcaller -from typing import Self import numpy as np import pytest @@ -43,7 +42,7 @@ def test_get_bool_data_preserve_dtype(self): def test_nonzero_single_element(self): # allow single item via bool method msg = ( - f"{type(Self).__name__}.bool is now deprecated and will be removed " + "Series.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning" ) @@ -66,7 +65,7 @@ def test_nonzero_single_element_raise_1(self, data): @pytest.mark.parametrize("data", [np.nan, pd.NaT]) def test_nonzero_single_element_raise_2(self, data): msg = ( - f"{type(Self).__name__}.bool is now deprecated and will be removed " + "Series.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning" ) @@ -80,15 +79,14 @@ def test_nonzero_single_element_raise_2(self, data): def test_nonzero_multiple_element_raise(self, data): # multiple bool are still an error msg = ( - f"{type(Self).__name__}.bool is now deprecated and will be removed " + "Series.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning" ) msg1 = "The truth value of a Series is ambiguous" series = Series([data]) - with tm.assert_produces_warning(FutureWarning, match=msg): - with pytest.raises(ValueError, match=msg1): - bool(series) + with pytest.raises(ValueError, match=msg1): + bool(series) with tm.assert_produces_warning(FutureWarning, match=msg): with pytest.raises(ValueError, match=msg1): series.bool() @@ -97,7 +95,7 @@ def test_nonzero_multiple_element_raise(self, data): def test_nonbool_single_element_raise(self, data): # single non-bool are an error msg = ( - f"{type(Self).__name__}.bool is now deprecated and will be removed " + "Series.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning" ) From 4908a89348ff9e8d63c37d45e987413149ac4d05 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 14 Mar 2023 16:13:55 +0530 Subject: [PATCH 22/37] Update conftest.py --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index e815aaa96dc59..5e6444613c326 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -139,7 +139,7 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - "NDFrame.bool is now deprecated and will be removed " + f"{type(self).__name__}.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning", ), From f3256db187d6af271723ed751cb29c51f5416497 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Wed, 15 Mar 2023 10:34:57 +0530 Subject: [PATCH 23/37] Update conftest.py --- pandas/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 5e6444613c326..1331ba1303dce 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -34,6 +34,7 @@ Callable, Hashable, Iterator, + Union, ) from dateutil.tz import ( @@ -139,7 +140,7 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - f"{type(self).__name__}.bool is now deprecated and will be removed " + f"{Union[Series,DataFrame]}.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning", ), From 0478351b8533cd517fdea7382f91b2de4d387643 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Wed, 15 Mar 2023 19:24:56 +0530 Subject: [PATCH 24/37] Update conftest.py --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 28c3766a153b9..ed636a85127ff 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -140,7 +140,7 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - f"{Union[Series,DataFrame]}.bool is now deprecated and will be removed " + f"{Series | DataFrame}.bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning", ), From 81882aa4b35a156e74b323a313315559e2a9e733 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 16 Mar 2023 12:41:00 +0530 Subject: [PATCH 25/37] Update conftest.py --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index ed636a85127ff..18528d19450c1 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -140,7 +140,7 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - f"{Series | DataFrame}.bool is now deprecated and will be removed " + "(Series | DataFrame).bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning", ), From 505c82b1c2989e6f51f8c8718e7da5306281e3c0 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 16 Mar 2023 12:42:27 +0530 Subject: [PATCH 26/37] Update conftest.py --- pandas/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 18528d19450c1..074277689b9bf 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -34,7 +34,6 @@ Callable, Hashable, Iterator, - Union, ) from dateutil.tz import ( From 84ab13d6aa1c7f096acad60ec40a3a7a75dcb81e Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 17 Mar 2023 10:38:38 +0530 Subject: [PATCH 27/37] Update conftest.py --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 074277689b9bf..a3b1afab5bc0d 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -139,7 +139,7 @@ def pytest_collection_modifyitems(items, config) -> None: ("missing.mask_zero_div_zero", "divide by zero encountered"), ( "pandas.core.generic.NDFrame.bool", - "(Series | DataFrame).bool is now deprecated and will be removed " + "(Series|DataFrame).bool is now deprecated and will be removed " "in future version of pandas and cases that relied on it will raise " "a future warning", ), From a8c90d58270037ed4ee0c8b96c58aa6cfd1887be Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 23 Mar 2023 10:32:24 +0530 Subject: [PATCH 28/37] added okwarning to docs build and whatsnew entry --- doc/source/whatsnew/v0.13.0.rst | 1 + doc/source/whatsnew/v2.1.0.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v0.13.0.rst b/doc/source/whatsnew/v0.13.0.rst index 8ce038200acc4..f91b4e0a3bb42 100644 --- a/doc/source/whatsnew/v0.13.0.rst +++ b/doc/source/whatsnew/v0.13.0.rst @@ -154,6 +154,7 @@ API changes Added the ``.bool()`` method to ``NDFrame`` objects to facilitate evaluating of single-element boolean Series: .. ipython:: python + :okwarning: pd.Series([True]).bool() pd.Series([False]).bool() diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 865fa3c6ac949..706de8169d3b3 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -103,6 +103,7 @@ Deprecations - Deprecated passing a :class:`DataFrame` to :meth:`DataFrame.from_records`, use :meth:`DataFrame.set_index` or :meth:`DataFrame.drop` instead (:issue:`51353`) - Deprecated accepting slices in :meth:`DataFrame.take`, call ``obj[slicer]`` or pass a sequence of integers instead (:issue:`51539`) - Deprecated 'method', 'limit', and 'fill_axis' keywords in :meth:`DataFrame.align` and :meth:`Series.align`, explicitly call ``fillna`` on the alignment results instead (:issue:`51856`) +- Deprecated '.bool' in :meth:`NDFrame.bool` (:issue:`51749`) - .. --------------------------------------------------------------------------- From baa2b12ea2ec07b592fb2b10206f95920d8eb077 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 23 Mar 2023 10:43:26 +0530 Subject: [PATCH 29/37] merged branches --- doc/source/whatsnew/v2.1.0.rst | 1 - pandas/tests/window/test_timeseries_window.py | 6 ------ 2 files changed, 7 deletions(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index bb72fcf6d1607..d2fe3a53a8078 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -109,7 +109,6 @@ Deprecations - Deprecated ``axis=1`` in :meth:`DataFrame.ewm`, :meth:`DataFrame.rolling`, :meth:`DataFrame.expanding`, transpose before calling the method instead (:issue:`51778`) - Deprecated the ``axis`` keyword in :meth:`DataFrame.ewm`, :meth:`Series.ewm`, :meth:`DataFrame.rolling`, :meth:`Series.rolling`, :meth:`DataFrame.expanding`, :meth:`Series.expanding` (:issue:`51778`) - Deprecated 'method', 'limit', and 'fill_axis' keywords in :meth:`DataFrame.align` and :meth:`Series.align`, explicitly call ``fillna`` on the alignment results instead (:issue:`51856`) -- Deprecated '.bool' in :meth:`NDFrame.bool` (:issue:`51749`) - Deprecated the 'axis' keyword in :meth:`.GroupBy.idxmax`, :meth:`.GroupBy.idxmin`, :meth:`.GroupBy.fillna`, :meth:`.GroupBy.take`, :meth:`.GroupBy.skew`, :meth:`.GroupBy.rank`, :meth:`.GroupBy.cumprod`, :meth:`.GroupBy.cumsum`, :meth:`.GroupBy.cummax`, :meth:`.GroupBy.cummin`, :meth:`.GroupBy.pct_change`, :meth:`GroupBy.diff`, :meth:`.GroupBy.shift`, and :meth:`DataFrameGroupBy.corrwith`; for ``axis=1`` operate on the underlying :class:`DataFrame` instead (:issue:`50405`, :issue:`51046`) - Deprecated '.bool' in :meth:`NDFrame.bool` (:issue:`51749`) - diff --git a/pandas/tests/window/test_timeseries_window.py b/pandas/tests/window/test_timeseries_window.py index 3a43a1c8e2414..9d79ddfe911ed 100644 --- a/pandas/tests/window/test_timeseries_window.py +++ b/pandas/tests/window/test_timeseries_window.py @@ -509,12 +509,6 @@ def test_perf_min(self): expected = dfp.rolling(2, min_periods=1).min() result = dfp.rolling("2s").min() - assert ((result - expected) < 0.01).all().bool() - - expected = dfp.rolling(200, min_periods=1).min() - result = dfp.rolling("200s").min() - assert ((result - expected) < 0.01).all().bool() - assert ((result - expected) < 0.01).all().all() expected = dfp.rolling(200, min_periods=1).min() From f62c490fd00488b943c2705da70cebe257b8e5f9 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 23 Mar 2023 11:02:23 +0530 Subject: [PATCH 30/37] Update v0.13.0.rst --- doc/source/whatsnew/v0.13.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.13.0.rst b/doc/source/whatsnew/v0.13.0.rst index f91b4e0a3bb42..f75788618778e 100644 --- a/doc/source/whatsnew/v0.13.0.rst +++ b/doc/source/whatsnew/v0.13.0.rst @@ -154,7 +154,7 @@ API changes Added the ``.bool()`` method to ``NDFrame`` objects to facilitate evaluating of single-element boolean Series: .. ipython:: python - :okwarning: + :okwarning: pd.Series([True]).bool() pd.Series([False]).bool() From b21328f6d05fad7acf08e8b457ba738f5b0df81f Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 23 Mar 2023 11:40:23 +0530 Subject: [PATCH 31/37] Update test_frame.py --- pandas/tests/generic/test_frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/generic/test_frame.py b/pandas/tests/generic/test_frame.py index 29561cf45cccd..d41d6f3ccd8de 100644 --- a/pandas/tests/generic/test_frame.py +++ b/pandas/tests/generic/test_frame.py @@ -54,7 +54,7 @@ def test_nonzero_single_element(self): ) df = DataFrame([[True]]) df1 = DataFrame([[False]]) - while tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg): assert df.bool() with tm.assert_produces_warning(FutureWarning, match=msg): From 712f0f670ff72f14d76882ef0e3064d74bd6b9aa Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 23 Mar 2023 12:07:23 +0530 Subject: [PATCH 32/37] Update test_frame.py --- pandas/tests/generic/test_frame.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/generic/test_frame.py b/pandas/tests/generic/test_frame.py index d41d6f3ccd8de..3bdf6b5cf76f3 100644 --- a/pandas/tests/generic/test_frame.py +++ b/pandas/tests/generic/test_frame.py @@ -61,12 +61,12 @@ def test_nonzero_single_element(self): assert not df1.bool() df = DataFrame([[False, False]]) - msg = "The truth value of a DataFrame is ambiguous" - with pytest.raises(ValueError, match=msg): + msg1 = "The truth value of a DataFrame is ambiguous" + with pytest.raises(ValueError, match=msg1): bool(df) with tm.assert_produces_warning(FutureWarning, match=msg): - with pytest.raises(ValueError, match=msg): + with pytest.raises(ValueError, match=msg1): df.bool() def test_metadata_propagation_indiv_groupby(self): From 2168bfd9e2582b7f6ceef06c85f849704a95b136 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 23 Mar 2023 23:31:23 +0530 Subject: [PATCH 33/37] Done required changes --- doc/source/whatsnew/v0.13.0.rst | 11 ++--- doc/source/whatsnew/v2.1.0.rst | 2 +- pandas/conftest.py | 3 +- pandas/core/generic.py | 3 +- pandas/tests/generic/test_frame.py | 17 ++++--- pandas/tests/generic/test_generic.py | 7 ++- pandas/tests/generic/test_series.py | 48 +++++++++---------- pandas/tests/window/test_timeseries_window.py | 1 - 8 files changed, 41 insertions(+), 51 deletions(-) diff --git a/doc/source/whatsnew/v0.13.0.rst b/doc/source/whatsnew/v0.13.0.rst index f75788618778e..09deb875cac09 100644 --- a/doc/source/whatsnew/v0.13.0.rst +++ b/doc/source/whatsnew/v0.13.0.rst @@ -153,13 +153,12 @@ API changes Added the ``.bool()`` method to ``NDFrame`` objects to facilitate evaluating of single-element boolean Series: - .. ipython:: python - :okwarning: + .. code-block:: python - pd.Series([True]).bool() - pd.Series([False]).bool() - pd.DataFrame([[True]]).bool() - pd.DataFrame([[False]]).bool() + >>> pd.Series([True]).bool() + >>> pd.Series([False]).bool() + >>> pd.DataFrame([[True]]).bool() + >>> pd.DataFrame([[False]]).bool() - All non-Index NDFrames (``Series``, ``DataFrame``, ``Panel``, ``Panel4D``, ``SparsePanel``, etc.), now support the entire set of arithmetic operators diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index d2fe3a53a8078..28376c24c4299 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -110,7 +110,7 @@ Deprecations - Deprecated the ``axis`` keyword in :meth:`DataFrame.ewm`, :meth:`Series.ewm`, :meth:`DataFrame.rolling`, :meth:`Series.rolling`, :meth:`DataFrame.expanding`, :meth:`Series.expanding` (:issue:`51778`) - Deprecated 'method', 'limit', and 'fill_axis' keywords in :meth:`DataFrame.align` and :meth:`Series.align`, explicitly call ``fillna`` on the alignment results instead (:issue:`51856`) - Deprecated the 'axis' keyword in :meth:`.GroupBy.idxmax`, :meth:`.GroupBy.idxmin`, :meth:`.GroupBy.fillna`, :meth:`.GroupBy.take`, :meth:`.GroupBy.skew`, :meth:`.GroupBy.rank`, :meth:`.GroupBy.cumprod`, :meth:`.GroupBy.cumsum`, :meth:`.GroupBy.cummax`, :meth:`.GroupBy.cummin`, :meth:`.GroupBy.pct_change`, :meth:`GroupBy.diff`, :meth:`.GroupBy.shift`, and :meth:`DataFrameGroupBy.corrwith`; for ``axis=1`` operate on the underlying :class:`DataFrame` instead (:issue:`50405`, :issue:`51046`) -- Deprecated '.bool' in :meth:`NDFrame.bool` (:issue:`51749`) +- Deprecated the methods :meth:`Series.bool` and :meth:`DataFrame.bool` (:issue:`51749`) - .. --------------------------------------------------------------------------- diff --git a/pandas/conftest.py b/pandas/conftest.py index 2ccdf061a986c..2d7e1faac2a9f 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -140,8 +140,7 @@ def pytest_collection_modifyitems(items, config) -> None: ( "pandas.core.generic.NDFrame.bool", "(Series|DataFrame).bool is now deprecated and will be removed " - "in future version of pandas and cases that relied on it will raise " - "a future warning", + "in future version of pandas", ), ] diff --git a/pandas/core/generic.py b/pandas/core/generic.py index be4b555b504f7..f6770682e4e69 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1507,8 +1507,7 @@ def bool(self) -> bool_t: warnings.warn( f"{type(self).__name__}.bool is now deprecated and will be removed " - "in future version of pandas and cases that relied on it will raise " - "a future warning", + "in future version of pandas", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/tests/generic/test_frame.py b/pandas/tests/generic/test_frame.py index 3bdf6b5cf76f3..79f055909fdea 100644 --- a/pandas/tests/generic/test_frame.py +++ b/pandas/tests/generic/test_frame.py @@ -47,26 +47,25 @@ def test_set_axis_name_mi(self, func): def test_nonzero_single_element(self): # allow single item via bool method - msg = ( + msg_warn = ( "DataFrame.bool is now deprecated and will be removed " - "in future version of pandas and cases that relied on it will raise " - "a future warning" + "in future version of pandas" ) df = DataFrame([[True]]) df1 = DataFrame([[False]]) - with tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg_warn): assert df.bool() - with tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg_warn): assert not df1.bool() df = DataFrame([[False, False]]) - msg1 = "The truth value of a DataFrame is ambiguous" - with pytest.raises(ValueError, match=msg1): + msg_err = "The truth value of a DataFrame is ambiguous" + with pytest.raises(ValueError, match=msg_err): bool(df) - with tm.assert_produces_warning(FutureWarning, match=msg): - with pytest.raises(ValueError, match=msg1): + with tm.assert_produces_warning(FutureWarning, match=msg_warn): + with pytest.raises(ValueError, match=msg_err): df.bool() def test_metadata_propagation_indiv_groupby(self): diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 47b9141dc0c70..26b006dfa26d8 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -450,10 +450,9 @@ def test_flags_identity(self, frame_or_series): assert obj2.flags is not obj.flags def test_bool_dep(self) -> None: - msg = ( + msg_warn = ( "DataFrame.bool is now deprecated and will be removed " - "in future version of pandas and cases that relied on it will raise " - "a future warning" + "in future version of pandas" ) - with tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg_warn): DataFrame({"col": [False]}).bool() diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index c4941d27e393c..ee0a7fb77f336 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -41,16 +41,15 @@ def test_get_bool_data_preserve_dtype(self): def test_nonzero_single_element(self): # allow single item via bool method - msg = ( + msg_warn = ( "Series.bool is now deprecated and will be removed " - "in future version of pandas and cases that relied on it will raise " - "a future warning" + "in future version of pandas" ) ser = Series([True]) ser1 = Series([False]) - with tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg_warn): assert ser.bool() - with tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg_warn): assert not ser1.bool() @pytest.mark.parametrize("data", [np.nan, pd.NaT, True, False]) @@ -64,48 +63,45 @@ def test_nonzero_single_element_raise_1(self, data): @pytest.mark.parametrize("data", [np.nan, pd.NaT]) def test_nonzero_single_element_raise_2(self, data): - msg = ( + msg_warn = ( "Series.bool is now deprecated and will be removed " - "in future version of pandas and cases that relied on it will raise " - "a future warning" + "in future version of pandas" ) - msg1 = "bool cannot act on a non-boolean single element Series" + msg_err = "bool cannot act on a non-boolean single element Series" series = Series([data]) - with tm.assert_produces_warning(FutureWarning, match=msg): - with pytest.raises(ValueError, match=msg1): + with tm.assert_produces_warning(FutureWarning, match=msg_warn): + with pytest.raises(ValueError, match=msg_err): series.bool() @pytest.mark.parametrize("data", [(True, True), (False, False)]) def test_nonzero_multiple_element_raise(self, data): # multiple bool are still an error - msg = ( + msg_warn = ( "Series.bool is now deprecated and will be removed " - "in future version of pandas and cases that relied on it will raise " - "a future warning" + "in future version of pandas" ) - msg1 = "The truth value of a Series is ambiguous" + msg_err = "The truth value of a Series is ambiguous" series = Series([data]) - with pytest.raises(ValueError, match=msg1): + with pytest.raises(ValueError, match=msg_err): bool(series) - with tm.assert_produces_warning(FutureWarning, match=msg): - with pytest.raises(ValueError, match=msg1): + with tm.assert_produces_warning(FutureWarning, match=msg_warn): + with pytest.raises(ValueError, match=msg_err): series.bool() @pytest.mark.parametrize("data", [1, 0, "a", 0.0]) def test_nonbool_single_element_raise(self, data): # single non-bool are an error - msg = ( + msg_warn = ( "Series.bool is now deprecated and will be removed " - "in future version of pandas and cases that relied on it will raise " - "a future warning" + "in future version of pandas" ) - msg1 = "The truth value of a Series is ambiguous" - msg2 = "bool cannot act on a non-boolean single element Series" + msg_err1 = "The truth value of a Series is ambiguous" + msg_err2 = "bool cannot act on a non-boolean single element Series" series = Series([data]) - with pytest.raises(ValueError, match=msg1): + with pytest.raises(ValueError, match=msg_err1): bool(series) - with tm.assert_produces_warning(FutureWarning, match=msg): - with pytest.raises(ValueError, match=msg2): + with tm.assert_produces_warning(FutureWarning, match=msg_warn): + with pytest.raises(ValueError, match=msg_err2): series.bool() def test_metadata_propagation_indiv_resample(self): diff --git a/pandas/tests/window/test_timeseries_window.py b/pandas/tests/window/test_timeseries_window.py index 9d79ddfe911ed..265ef29e42c48 100644 --- a/pandas/tests/window/test_timeseries_window.py +++ b/pandas/tests/window/test_timeseries_window.py @@ -506,7 +506,6 @@ def test_perf_min(self): dfp = DataFrame( {"B": np.random.randn(N)}, index=date_range("20130101", periods=N, freq="s") ) - expected = dfp.rolling(2, min_periods=1).min() result = dfp.rolling("2s").min() assert ((result - expected) < 0.01).all().all() From c3c2c30c38296a1d4158c3b1df7fd5404f8a069e Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 24 Mar 2023 01:33:09 +0530 Subject: [PATCH 34/37] Update test_generic.py --- pandas/tests/generic/test_generic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 26b006dfa26d8..5acb61ca24a29 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -450,6 +450,7 @@ def test_flags_identity(self, frame_or_series): assert obj2.flags is not obj.flags def test_bool_dep(self) -> None: + # GH-51749 msg_warn = ( "DataFrame.bool is now deprecated and will be removed " "in future version of pandas" From 5ef23739f14415e092e1c2b1920729a8db7ff0e4 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 31 Mar 2023 12:00:56 +0530 Subject: [PATCH 35/37] Update v0.13.0.rst --- doc/source/whatsnew/v0.13.0.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.13.0.rst b/doc/source/whatsnew/v0.13.0.rst index 09deb875cac09..b112f7e9c1cfb 100644 --- a/doc/source/whatsnew/v0.13.0.rst +++ b/doc/source/whatsnew/v0.13.0.rst @@ -156,11 +156,15 @@ API changes .. code-block:: python >>> pd.Series([True]).bool() + .. True >>> pd.Series([False]).bool() + .. False >>> pd.DataFrame([[True]]).bool() + .. True >>> pd.DataFrame([[False]]).bool() + .. False -- All non-Index NDFrames (``Series``, ``DataFrame``, ``Panel``, ``Panel4D``, +- All non-Index NDFrames ( ``Series``, ``DataFrame``, ``Panel``, ``Panel4D``, ``SparsePanel``, etc.), now support the entire set of arithmetic operators and arithmetic flex methods (add, sub, mul, etc.). ``SparsePanel`` does not support ``pow`` or ``mod`` with non-scalars. (:issue:`3765`) From 1a9b06e8dffffed633b435f05dddee37842e94a1 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 31 Mar 2023 12:11:14 +0530 Subject: [PATCH 36/37] Update v2.1.0.rst --- doc/source/whatsnew/v2.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 6fac5a582d956..8d1dc73f8bec1 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -123,9 +123,9 @@ Deprecations - Deprecated 'broadcast_axis' keyword in :meth:`Series.align` and :meth:`DataFrame.align`, upcast before calling ``align`` with ``left = DataFrame({col: left for col in right.columns}, index=right.index)`` (:issue:`51856`) - Deprecated the 'axis' keyword in :meth:`.GroupBy.idxmax`, :meth:`.GroupBy.idxmin`, :meth:`.GroupBy.fillna`, :meth:`.GroupBy.take`, :meth:`.GroupBy.skew`, :meth:`.GroupBy.rank`, :meth:`.GroupBy.cumprod`, :meth:`.GroupBy.cumsum`, :meth:`.GroupBy.cummax`, :meth:`.GroupBy.cummin`, :meth:`.GroupBy.pct_change`, :meth:`GroupBy.diff`, :meth:`.GroupBy.shift`, and :meth:`DataFrameGroupBy.corrwith`; for ``axis=1`` operate on the underlying :class:`DataFrame` instead (:issue:`50405`, :issue:`51046`) - Deprecated logical operations (``|``, ``&``, ``^``) between pandas objects and dtype-less sequences (e.g. ``list``, ``tuple``), wrap a sequence in a :class:`Series` or numpy array before operating instead (:issue:`51521`) +- Deprecated the methods :meth:`Series.bool` and :meth:`DataFrame.bool` (:issue:`51749`) - Deprecated :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes`, use :meth:`DataFrame.transpose` or :meth:`Series.transpose` instead (:issue:`51946`) - Deprecated parameter ``convert_type`` in :meth:`Series.apply` (:issue:`52140`) -- Deprecated the methods :meth:`Series.bool` and :meth:`DataFrame.bool` (:issue:`51749`) - .. --------------------------------------------------------------------------- From 014d685b547cfaf4e5a90be9e1c6a5c14eb6779a Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 1 Apr 2023 08:14:28 +0530 Subject: [PATCH 37/37] Update v0.13.0.rst --- doc/source/whatsnew/v0.13.0.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v0.13.0.rst b/doc/source/whatsnew/v0.13.0.rst index b112f7e9c1cfb..2e086f560bd53 100644 --- a/doc/source/whatsnew/v0.13.0.rst +++ b/doc/source/whatsnew/v0.13.0.rst @@ -156,15 +156,15 @@ API changes .. code-block:: python >>> pd.Series([True]).bool() - .. True + True >>> pd.Series([False]).bool() - .. False + False >>> pd.DataFrame([[True]]).bool() - .. True + True >>> pd.DataFrame([[False]]).bool() - .. False + False -- All non-Index NDFrames ( ``Series``, ``DataFrame``, ``Panel``, ``Panel4D``, +- All non-Index NDFrames (``Series``, ``DataFrame``, ``Panel``, ``Panel4D``, ``SparsePanel``, etc.), now support the entire set of arithmetic operators and arithmetic flex methods (add, sub, mul, etc.). ``SparsePanel`` does not support ``pow`` or ``mod`` with non-scalars. (:issue:`3765`)