From da3c79aeec83b00ef19eb83538649b28e9750d3e Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Sun, 22 Dec 2019 17:34:43 +0530 Subject: [PATCH 01/20] update dedeprecation message for np.ptp DEPR #28665 #6581 --- pandas/core/generic.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 15789f0fb095a..84bdef34189a8 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10198,7 +10198,10 @@ def nanptp(values, axis=0, skipna=True): nmin = nanops.nanmin(values, axis, skipna) warnings.warn( "Method .ptp is deprecated and will be removed " - "in a future version. Use numpy.ptp instead.", + "in a future version. Use numpy.ptp instead." + "if you are already using numpy.ptp and still getting this message" + "please call to_numpy() to avoid this message in future calls" + "eg : np.ptp(pd.Series([1, 2, 3]).to_numpy())", FutureWarning, stacklevel=4, ) From d89d7f657aba51ed90a4f04e31c1e30c4540ee31 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Mon, 23 Dec 2019 22:22:30 +0530 Subject: [PATCH 02/20] update dedeprecation message for np.ptp DEPR #28665 #6581 requested changes made --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 84bdef34189a8..4f11c3c88176e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10199,9 +10199,9 @@ def nanptp(values, axis=0, skipna=True): warnings.warn( "Method .ptp is deprecated and will be removed " "in a future version. Use numpy.ptp instead." - "if you are already using numpy.ptp and still getting this message" - "please call to_numpy() to avoid this message in future calls" - "eg : np.ptp(pd.Series([1, 2, 3]).to_numpy())", + "if you are already using numpy.ptp and still getting this message," + "please call to_numpy() to avoid this message in future calls." + "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", FutureWarning, stacklevel=4, ) From d9e955e27ac6ae35d5c3423585323238cb9d11dd Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Tue, 24 Dec 2019 02:33:52 +0530 Subject: [PATCH 03/20] remove code for ptp() --- pandas/core/generic.py | 72 +++++++++++++-------------- pandas/core/series.py | 2 +- pandas/tests/series/test_analytics.py | 62 +++++++++++------------ 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4f11c3c88176e..6f787ed9179bd 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10184,42 +10184,42 @@ def mad(self, axis=None, skipna=None, level=None): _min_examples, ) - @classmethod - def _add_series_only_operations(cls): - """ - Add the series only operations to the cls; evaluate the doc - strings again. - """ - - axis_descr, name, name2 = _doc_parms(cls) - - def nanptp(values, axis=0, skipna=True): - nmax = nanops.nanmax(values, axis, skipna) - nmin = nanops.nanmin(values, axis, skipna) - warnings.warn( - "Method .ptp is deprecated and will be removed " - "in a future version. Use numpy.ptp instead." - "if you are already using numpy.ptp and still getting this message," - "please call to_numpy() to avoid this message in future calls." - "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", - FutureWarning, - stacklevel=4, - ) - return nmax - nmin - - cls.ptp = _make_stat_function( - cls, - "ptp", - name, - name2, - axis_descr, - """Return the difference between the min and max value. - \n.. deprecated:: 0.24.0 Use numpy.ptp instead - \nReturn the difference between the maximum value and the - minimum value in the object. This is the equivalent of the - ``numpy.ndarray`` method ``ptp``.""", - nanptp, - ) + # @classmethod + # def _add_series_only_operations(cls): + # """ + # Add the series only operations to the cls; evaluate the doc + # strings again. + # """ + + # axis_descr, name, name2 = _doc_parms(cls) + + # def nanptp(values, axis=0, skipna=True): + # nmax = nanops.nanmax(values, axis, skipna) + # nmin = nanops.nanmin(values, axis, skipna) + # warnings.warn( + # "Method .ptp is deprecated and will be removed " + # "in a future version. Use numpy.ptp instead." + # "if you are already using numpy.ptp and still getting this message," + # "please call to_numpy() to avoid this message in future calls." + # "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", + # FutureWarning, + # stacklevel=4, + # ) + # return nmax - nmin + + # cls.ptp = _make_stat_function( + # cls, + # "ptp", + # name, + # name2, + # axis_descr, + # """Return the difference between the min and max value. + # \n.. deprecated:: 0.24.0 Use numpy.ptp instead + # \nReturn the difference between the maximum value and the + # minimum value in the object. This is the equivalent of the + # ``numpy.ndarray`` method ``ptp``.""", + # nanptp, + # ) @classmethod def _add_series_or_dataframe_operations(cls): diff --git a/pandas/core/series.py b/pandas/core/series.py index 54c163330e6ee..392d3cf33cc2b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4390,7 +4390,7 @@ def to_period(self, freq=None, copy=True): ["index"], docs={"index": "The index (axis labels) of the Series."}, ) Series._add_numeric_operations() -Series._add_series_only_operations() +# Series._add_series_only_operations() Series._add_series_or_dataframe_operations() # Add arithmetic! diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 0eb4e8a6cfdf3..c474f00e52c35 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -861,37 +861,37 @@ def test_ptp(self): assert np.ptp(ser) == np.ptp(arr) # GH11163 - s = Series([3, 5, np.nan, -3, 10]) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert s.ptp() == 13 - assert pd.isna(s.ptp(skipna=False)) - - mi = pd.MultiIndex.from_product([["a", "b"], [1, 2, 3]]) - s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi) - - expected = pd.Series([6, 2], index=["a", "b"], dtype=np.float64) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - tm.assert_series_equal(s.ptp(level=0), expected) - - expected = pd.Series([np.nan, np.nan], index=["a", "b"]) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) - - msg = "No axis named 1 for object type " - with pytest.raises(ValueError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s.ptp(axis=1) - - s = pd.Series(["a", "b", "c", "d", "e"]) - msg = r"unsupported operand type\(s\) for -: 'str' and 'str'" - with pytest.raises(TypeError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s.ptp() - - msg = r"Series\.ptp does not implement numeric_only\." - with pytest.raises(NotImplementedError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s.ptp(numeric_only=True) + # s = Series([3, 5, np.nan, -3, 10]) + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # assert s.ptp() == 13 + # assert pd.isna(s.ptp(skipna=False)) + + # mi = pd.MultiIndex.from_product([["a", "b"], [1, 2, 3]]) + # s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi) + + # expected = pd.Series([6, 2], index=["a", "b"], dtype=np.float64) + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # tm.assert_series_equal(s.ptp(level=0), expected) + + # expected = pd.Series([np.nan, np.nan], index=["a", "b"]) + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) + + # msg = "No axis named 1 for object type " + # with pytest.raises(ValueError, match=msg): + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # s.ptp(axis=1) + + # s = pd.Series(["a", "b", "c", "d", "e"]) + # msg = r"unsupported operand type\(s\) for -: 'str' and 'str'" + # with pytest.raises(TypeError, match=msg): + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # s.ptp() + + # msg = r"Series\.ptp does not implement numeric_only\." + # with pytest.raises(NotImplementedError, match=msg): + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # s.ptp(numeric_only=True) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From 08a5f3e90b9477b3e2d99601626760c5072d0095 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Tue, 24 Dec 2019 02:51:51 +0530 Subject: [PATCH 04/20] remove comments) --- pandas/core/generic.py | 37 --------------------------- pandas/core/series.py | 1 - pandas/tests/series/test_analytics.py | 34 +----------------------- 3 files changed, 1 insertion(+), 71 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6f787ed9179bd..cc7983f9c95c5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10184,43 +10184,6 @@ def mad(self, axis=None, skipna=None, level=None): _min_examples, ) - # @classmethod - # def _add_series_only_operations(cls): - # """ - # Add the series only operations to the cls; evaluate the doc - # strings again. - # """ - - # axis_descr, name, name2 = _doc_parms(cls) - - # def nanptp(values, axis=0, skipna=True): - # nmax = nanops.nanmax(values, axis, skipna) - # nmin = nanops.nanmin(values, axis, skipna) - # warnings.warn( - # "Method .ptp is deprecated and will be removed " - # "in a future version. Use numpy.ptp instead." - # "if you are already using numpy.ptp and still getting this message," - # "please call to_numpy() to avoid this message in future calls." - # "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", - # FutureWarning, - # stacklevel=4, - # ) - # return nmax - nmin - - # cls.ptp = _make_stat_function( - # cls, - # "ptp", - # name, - # name2, - # axis_descr, - # """Return the difference between the min and max value. - # \n.. deprecated:: 0.24.0 Use numpy.ptp instead - # \nReturn the difference between the maximum value and the - # minimum value in the object. This is the equivalent of the - # ``numpy.ndarray`` method ``ptp``.""", - # nanptp, - # ) - @classmethod def _add_series_or_dataframe_operations(cls): """ diff --git a/pandas/core/series.py b/pandas/core/series.py index 392d3cf33cc2b..4ed903d41a7a0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4390,7 +4390,6 @@ def to_period(self, freq=None, copy=True): ["index"], docs={"index": "The index (axis labels) of the Series."}, ) Series._add_numeric_operations() -# Series._add_series_only_operations() Series._add_series_or_dataframe_operations() # Add arithmetic! diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index c474f00e52c35..819705b4f031c 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -858,41 +858,9 @@ def test_ptp(self): arr = np.random.randn(N) ser = Series(arr) with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + print("hell") assert np.ptp(ser) == np.ptp(arr) - # GH11163 - # s = Series([3, 5, np.nan, -3, 10]) - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # assert s.ptp() == 13 - # assert pd.isna(s.ptp(skipna=False)) - - # mi = pd.MultiIndex.from_product([["a", "b"], [1, 2, 3]]) - # s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi) - - # expected = pd.Series([6, 2], index=["a", "b"], dtype=np.float64) - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # tm.assert_series_equal(s.ptp(level=0), expected) - - # expected = pd.Series([np.nan, np.nan], index=["a", "b"]) - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) - - # msg = "No axis named 1 for object type " - # with pytest.raises(ValueError, match=msg): - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # s.ptp(axis=1) - - # s = pd.Series(["a", "b", "c", "d", "e"]) - # msg = r"unsupported operand type\(s\) for -: 'str' and 'str'" - # with pytest.raises(TypeError, match=msg): - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # s.ptp() - - # msg = r"Series\.ptp does not implement numeric_only\." - # with pytest.raises(NotImplementedError, match=msg): - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # s.ptp(numeric_only=True) - def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From 3df0283f072e10b9c1ab84334239a973a45f6c5a Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Tue, 24 Dec 2019 02:54:49 +0530 Subject: [PATCH 05/20] remove comments --- pandas/tests/series/test_analytics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 819705b4f031c..e40b57ed27ada 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -858,7 +858,6 @@ def test_ptp(self): arr = np.random.randn(N) ser = Series(arr) with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - print("hell") assert np.ptp(ser) == np.ptp(arr) def test_repeat(self): From add3e23547b44b4628d722575889f9c14eec7996 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Tue, 24 Dec 2019 09:23:52 +0530 Subject: [PATCH 06/20] solve errors --- pandas/tests/series/test_analytics.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index e40b57ed27ada..d093a0775ab53 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -857,8 +857,7 @@ def test_ptp(self): N = 1000 arr = np.random.randn(N) ser = Series(arr) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert np.ptp(ser) == np.ptp(arr) + assert np.ptp(ser) == np.ptp(arr) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From b28bc3ab43396dc4fe707637015d705b5482ada9 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Tue, 24 Dec 2019 12:18:10 +0530 Subject: [PATCH 07/20] test at which command azure pipelines failing --- pandas/tests/series/test_analytics.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index d093a0775ab53..11dbd90a375e1 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -857,7 +857,9 @@ def test_ptp(self): N = 1000 arr = np.random.randn(N) ser = Series(arr) - assert np.ptp(ser) == np.ptp(arr) + ptp_np = np.ptp(arr) + ptp_pd = np.ptp(ser) + assert ptp_pd == ptp_np def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From 86c11c96cb32314a9487cc19e05d4b02b9615429 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Tue, 24 Dec 2019 13:21:38 +0530 Subject: [PATCH 08/20] use numpy.array_equal instead of == --- pandas/tests/series/test_analytics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 11dbd90a375e1..2382f61429711 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -859,7 +859,8 @@ def test_ptp(self): ser = Series(arr) ptp_np = np.ptp(arr) ptp_pd = np.ptp(ser) - assert ptp_pd == ptp_np + + assert np.array_equal(ptp_pd, ptp_np) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From 5d8d35f9a918a5a37e6f035201b242887a407748 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Tue, 24 Dec 2019 13:21:51 +0530 Subject: [PATCH 09/20] use numpy.array_equal instead of == --- pandas/tests/series/test_analytics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 2382f61429711..b77b190817115 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -859,7 +859,6 @@ def test_ptp(self): ser = Series(arr) ptp_np = np.ptp(arr) ptp_pd = np.ptp(ser) - assert np.array_equal(ptp_pd, ptp_np) def test_repeat(self): From c9ee01aa65fe061b3e6353bf12470a4f2a53cce2 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 01:32:34 +0530 Subject: [PATCH 10/20] Revert "use numpy.array_equal instead of ==" This reverts commit 5d8d35f9a918a5a37e6f035201b242887a407748. --- pandas/tests/series/test_analytics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index b77b190817115..2382f61429711 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -859,6 +859,7 @@ def test_ptp(self): ser = Series(arr) ptp_np = np.ptp(arr) ptp_pd = np.ptp(ser) + assert np.array_equal(ptp_pd, ptp_np) def test_repeat(self): From 0610de5b30bde7cb3492f2d4e998eb0f1f66196f Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 01:34:16 +0530 Subject: [PATCH 11/20] Revert "use numpy.array_equal instead of ==" This reverts commit 86c11c96cb32314a9487cc19e05d4b02b9615429. --- pandas/tests/series/test_analytics.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 2382f61429711..11dbd90a375e1 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -859,8 +859,7 @@ def test_ptp(self): ser = Series(arr) ptp_np = np.ptp(arr) ptp_pd = np.ptp(ser) - - assert np.array_equal(ptp_pd, ptp_np) + assert ptp_pd == ptp_np def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From f1e82abe1ff222f7fa37bbdfb228776201821da4 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 01:34:24 +0530 Subject: [PATCH 12/20] Revert "test at which command azure pipelines failing" This reverts commit b28bc3ab43396dc4fe707637015d705b5482ada9. --- pandas/tests/series/test_analytics.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 11dbd90a375e1..d093a0775ab53 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -857,9 +857,7 @@ def test_ptp(self): N = 1000 arr = np.random.randn(N) ser = Series(arr) - ptp_np = np.ptp(arr) - ptp_pd = np.ptp(ser) - assert ptp_pd == ptp_np + assert np.ptp(ser) == np.ptp(arr) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From d8b649e7133e016d1e01b7fd485253267798810a Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 01:34:25 +0530 Subject: [PATCH 13/20] Revert "solve errors" This reverts commit add3e23547b44b4628d722575889f9c14eec7996. --- pandas/tests/series/test_analytics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index d093a0775ab53..e40b57ed27ada 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -857,7 +857,8 @@ def test_ptp(self): N = 1000 arr = np.random.randn(N) ser = Series(arr) - assert np.ptp(ser) == np.ptp(arr) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + assert np.ptp(ser) == np.ptp(arr) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From eeba7061c42f1e75c5c3860af803b17c785dd2dd Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 01:34:26 +0530 Subject: [PATCH 14/20] Revert "remove comments" This reverts commit 3df0283f072e10b9c1ab84334239a973a45f6c5a. --- pandas/tests/series/test_analytics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index e40b57ed27ada..819705b4f031c 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -858,6 +858,7 @@ def test_ptp(self): arr = np.random.randn(N) ser = Series(arr) with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + print("hell") assert np.ptp(ser) == np.ptp(arr) def test_repeat(self): From 0c19cd3bf98d744204db31853f261fe6a82b6e51 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 01:34:26 +0530 Subject: [PATCH 15/20] Revert "remove comments)" This reverts commit 08a5f3e90b9477b3e2d99601626760c5072d0095. --- pandas/core/generic.py | 37 +++++++++++++++++++++++++++ pandas/core/series.py | 1 + pandas/tests/series/test_analytics.py | 34 +++++++++++++++++++++++- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index cc7983f9c95c5..6f787ed9179bd 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10184,6 +10184,43 @@ def mad(self, axis=None, skipna=None, level=None): _min_examples, ) + # @classmethod + # def _add_series_only_operations(cls): + # """ + # Add the series only operations to the cls; evaluate the doc + # strings again. + # """ + + # axis_descr, name, name2 = _doc_parms(cls) + + # def nanptp(values, axis=0, skipna=True): + # nmax = nanops.nanmax(values, axis, skipna) + # nmin = nanops.nanmin(values, axis, skipna) + # warnings.warn( + # "Method .ptp is deprecated and will be removed " + # "in a future version. Use numpy.ptp instead." + # "if you are already using numpy.ptp and still getting this message," + # "please call to_numpy() to avoid this message in future calls." + # "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", + # FutureWarning, + # stacklevel=4, + # ) + # return nmax - nmin + + # cls.ptp = _make_stat_function( + # cls, + # "ptp", + # name, + # name2, + # axis_descr, + # """Return the difference between the min and max value. + # \n.. deprecated:: 0.24.0 Use numpy.ptp instead + # \nReturn the difference between the maximum value and the + # minimum value in the object. This is the equivalent of the + # ``numpy.ndarray`` method ``ptp``.""", + # nanptp, + # ) + @classmethod def _add_series_or_dataframe_operations(cls): """ diff --git a/pandas/core/series.py b/pandas/core/series.py index 4ed903d41a7a0..392d3cf33cc2b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4390,6 +4390,7 @@ def to_period(self, freq=None, copy=True): ["index"], docs={"index": "The index (axis labels) of the Series."}, ) Series._add_numeric_operations() +# Series._add_series_only_operations() Series._add_series_or_dataframe_operations() # Add arithmetic! diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 819705b4f031c..c474f00e52c35 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -858,9 +858,41 @@ def test_ptp(self): arr = np.random.randn(N) ser = Series(arr) with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - print("hell") assert np.ptp(ser) == np.ptp(arr) + # GH11163 + # s = Series([3, 5, np.nan, -3, 10]) + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # assert s.ptp() == 13 + # assert pd.isna(s.ptp(skipna=False)) + + # mi = pd.MultiIndex.from_product([["a", "b"], [1, 2, 3]]) + # s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi) + + # expected = pd.Series([6, 2], index=["a", "b"], dtype=np.float64) + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # tm.assert_series_equal(s.ptp(level=0), expected) + + # expected = pd.Series([np.nan, np.nan], index=["a", "b"]) + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) + + # msg = "No axis named 1 for object type " + # with pytest.raises(ValueError, match=msg): + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # s.ptp(axis=1) + + # s = pd.Series(["a", "b", "c", "d", "e"]) + # msg = r"unsupported operand type\(s\) for -: 'str' and 'str'" + # with pytest.raises(TypeError, match=msg): + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # s.ptp() + + # msg = r"Series\.ptp does not implement numeric_only\." + # with pytest.raises(NotImplementedError, match=msg): + # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # s.ptp(numeric_only=True) + def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From ab8343a51af1087d97ade4d1aa5c8da3dc0947c8 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 01:34:27 +0530 Subject: [PATCH 16/20] Revert "remove code for ptp()" This reverts commit d9e955e27ac6ae35d5c3423585323238cb9d11dd. --- pandas/core/generic.py | 72 +++++++++++++-------------- pandas/core/series.py | 2 +- pandas/tests/series/test_analytics.py | 62 +++++++++++------------ 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6f787ed9179bd..4f11c3c88176e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10184,42 +10184,42 @@ def mad(self, axis=None, skipna=None, level=None): _min_examples, ) - # @classmethod - # def _add_series_only_operations(cls): - # """ - # Add the series only operations to the cls; evaluate the doc - # strings again. - # """ - - # axis_descr, name, name2 = _doc_parms(cls) - - # def nanptp(values, axis=0, skipna=True): - # nmax = nanops.nanmax(values, axis, skipna) - # nmin = nanops.nanmin(values, axis, skipna) - # warnings.warn( - # "Method .ptp is deprecated and will be removed " - # "in a future version. Use numpy.ptp instead." - # "if you are already using numpy.ptp and still getting this message," - # "please call to_numpy() to avoid this message in future calls." - # "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", - # FutureWarning, - # stacklevel=4, - # ) - # return nmax - nmin - - # cls.ptp = _make_stat_function( - # cls, - # "ptp", - # name, - # name2, - # axis_descr, - # """Return the difference between the min and max value. - # \n.. deprecated:: 0.24.0 Use numpy.ptp instead - # \nReturn the difference between the maximum value and the - # minimum value in the object. This is the equivalent of the - # ``numpy.ndarray`` method ``ptp``.""", - # nanptp, - # ) + @classmethod + def _add_series_only_operations(cls): + """ + Add the series only operations to the cls; evaluate the doc + strings again. + """ + + axis_descr, name, name2 = _doc_parms(cls) + + def nanptp(values, axis=0, skipna=True): + nmax = nanops.nanmax(values, axis, skipna) + nmin = nanops.nanmin(values, axis, skipna) + warnings.warn( + "Method .ptp is deprecated and will be removed " + "in a future version. Use numpy.ptp instead." + "if you are already using numpy.ptp and still getting this message," + "please call to_numpy() to avoid this message in future calls." + "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", + FutureWarning, + stacklevel=4, + ) + return nmax - nmin + + cls.ptp = _make_stat_function( + cls, + "ptp", + name, + name2, + axis_descr, + """Return the difference between the min and max value. + \n.. deprecated:: 0.24.0 Use numpy.ptp instead + \nReturn the difference between the maximum value and the + minimum value in the object. This is the equivalent of the + ``numpy.ndarray`` method ``ptp``.""", + nanptp, + ) @classmethod def _add_series_or_dataframe_operations(cls): diff --git a/pandas/core/series.py b/pandas/core/series.py index 392d3cf33cc2b..54c163330e6ee 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4390,7 +4390,7 @@ def to_period(self, freq=None, copy=True): ["index"], docs={"index": "The index (axis labels) of the Series."}, ) Series._add_numeric_operations() -# Series._add_series_only_operations() +Series._add_series_only_operations() Series._add_series_or_dataframe_operations() # Add arithmetic! diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index c474f00e52c35..0eb4e8a6cfdf3 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -861,37 +861,37 @@ def test_ptp(self): assert np.ptp(ser) == np.ptp(arr) # GH11163 - # s = Series([3, 5, np.nan, -3, 10]) - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # assert s.ptp() == 13 - # assert pd.isna(s.ptp(skipna=False)) - - # mi = pd.MultiIndex.from_product([["a", "b"], [1, 2, 3]]) - # s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi) - - # expected = pd.Series([6, 2], index=["a", "b"], dtype=np.float64) - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # tm.assert_series_equal(s.ptp(level=0), expected) - - # expected = pd.Series([np.nan, np.nan], index=["a", "b"]) - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) - - # msg = "No axis named 1 for object type " - # with pytest.raises(ValueError, match=msg): - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # s.ptp(axis=1) - - # s = pd.Series(["a", "b", "c", "d", "e"]) - # msg = r"unsupported operand type\(s\) for -: 'str' and 'str'" - # with pytest.raises(TypeError, match=msg): - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # s.ptp() - - # msg = r"Series\.ptp does not implement numeric_only\." - # with pytest.raises(NotImplementedError, match=msg): - # with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # s.ptp(numeric_only=True) + s = Series([3, 5, np.nan, -3, 10]) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + assert s.ptp() == 13 + assert pd.isna(s.ptp(skipna=False)) + + mi = pd.MultiIndex.from_product([["a", "b"], [1, 2, 3]]) + s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi) + + expected = pd.Series([6, 2], index=["a", "b"], dtype=np.float64) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + tm.assert_series_equal(s.ptp(level=0), expected) + + expected = pd.Series([np.nan, np.nan], index=["a", "b"]) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) + + msg = "No axis named 1 for object type " + with pytest.raises(ValueError, match=msg): + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + s.ptp(axis=1) + + s = pd.Series(["a", "b", "c", "d", "e"]) + msg = r"unsupported operand type\(s\) for -: 'str' and 'str'" + with pytest.raises(TypeError, match=msg): + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + s.ptp() + + msg = r"Series\.ptp does not implement numeric_only\." + with pytest.raises(NotImplementedError, match=msg): + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + s.ptp(numeric_only=True) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From 69d1c0aece14f34a4a67004da99be79bf9f81899 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 01:34:27 +0530 Subject: [PATCH 17/20] Revert "update dedeprecation message for np.ptp DEPR #28665 #6581 requested changes made" This reverts commit d89d7f657aba51ed90a4f04e31c1e30c4540ee31. --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4f11c3c88176e..84bdef34189a8 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10199,9 +10199,9 @@ def nanptp(values, axis=0, skipna=True): warnings.warn( "Method .ptp is deprecated and will be removed " "in a future version. Use numpy.ptp instead." - "if you are already using numpy.ptp and still getting this message," - "please call to_numpy() to avoid this message in future calls." - "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", + "if you are already using numpy.ptp and still getting this message" + "please call to_numpy() to avoid this message in future calls" + "eg : np.ptp(pd.Series([1, 2, 3]).to_numpy())", FutureWarning, stacklevel=4, ) From 8c0bb010fb7d247fc4ac1b40faa3c9f309b0ceac Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 01:59:14 +0530 Subject: [PATCH 18/20] removed ptp code and tests and also put a print statement to understand why azure build failing --- pandas/core/generic.py | 37 --------------------------- pandas/core/series.py | 1 - pandas/tests/series/test_analytics.py | 36 ++------------------------ 3 files changed, 2 insertions(+), 72 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 84bdef34189a8..cc7983f9c95c5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10184,43 +10184,6 @@ def mad(self, axis=None, skipna=None, level=None): _min_examples, ) - @classmethod - def _add_series_only_operations(cls): - """ - Add the series only operations to the cls; evaluate the doc - strings again. - """ - - axis_descr, name, name2 = _doc_parms(cls) - - def nanptp(values, axis=0, skipna=True): - nmax = nanops.nanmax(values, axis, skipna) - nmin = nanops.nanmin(values, axis, skipna) - warnings.warn( - "Method .ptp is deprecated and will be removed " - "in a future version. Use numpy.ptp instead." - "if you are already using numpy.ptp and still getting this message" - "please call to_numpy() to avoid this message in future calls" - "eg : np.ptp(pd.Series([1, 2, 3]).to_numpy())", - FutureWarning, - stacklevel=4, - ) - return nmax - nmin - - cls.ptp = _make_stat_function( - cls, - "ptp", - name, - name2, - axis_descr, - """Return the difference between the min and max value. - \n.. deprecated:: 0.24.0 Use numpy.ptp instead - \nReturn the difference between the maximum value and the - minimum value in the object. This is the equivalent of the - ``numpy.ndarray`` method ``ptp``.""", - nanptp, - ) - @classmethod def _add_series_or_dataframe_operations(cls): """ diff --git a/pandas/core/series.py b/pandas/core/series.py index 54c163330e6ee..4ed903d41a7a0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4390,7 +4390,6 @@ def to_period(self, freq=None, copy=True): ["index"], docs={"index": "The index (axis labels) of the Series."}, ) Series._add_numeric_operations() -Series._add_series_only_operations() Series._add_series_or_dataframe_operations() # Add arithmetic! diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 0eb4e8a6cfdf3..ff4901301d32a 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -857,41 +857,9 @@ def test_ptp(self): N = 1000 arr = np.random.randn(N) ser = Series(arr) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert np.ptp(ser) == np.ptp(arr) - - # GH11163 - s = Series([3, 5, np.nan, -3, 10]) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert s.ptp() == 13 - assert pd.isna(s.ptp(skipna=False)) - - mi = pd.MultiIndex.from_product([["a", "b"], [1, 2, 3]]) - s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi) - - expected = pd.Series([6, 2], index=["a", "b"], dtype=np.float64) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - tm.assert_series_equal(s.ptp(level=0), expected) - - expected = pd.Series([np.nan, np.nan], index=["a", "b"]) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) - - msg = "No axis named 1 for object type " - with pytest.raises(ValueError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s.ptp(axis=1) - - s = pd.Series(["a", "b", "c", "d", "e"]) - msg = r"unsupported operand type\(s\) for -: 'str' and 'str'" - with pytest.raises(TypeError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s.ptp() + print(np.ptp(ser), np.ptp(arr)) - msg = r"Series\.ptp does not implement numeric_only\." - with pytest.raises(NotImplementedError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s.ptp(numeric_only=True) + assert np.ptp(ser) == np.ptp(arr) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"]) From cc66afef1d24f781d1d8ac4528df7f48f07f7b6c Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 07:10:10 +0530 Subject: [PATCH 19/20] removed ptp code and tests and also put print statements to print type and values of ptp to understand why azure build failing --- pandas/tests/series/test_analytics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index ff4901301d32a..d5bbb6a11905b 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -858,7 +858,7 @@ def test_ptp(self): arr = np.random.randn(N) ser = Series(arr) print(np.ptp(ser), np.ptp(arr)) - + print(type(np.ptp(ser)), type(np.ptp(arr))) assert np.ptp(ser) == np.ptp(arr) def test_repeat(self): From d9e9ac76f23b3560aec59aeba59d8a94ef6cc318 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 25 Dec 2019 11:16:42 +0530 Subject: [PATCH 20/20] casting pandas to numpy before calling np.ptp() --- pandas/tests/series/test_analytics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index d5bbb6a11905b..e79670e686c52 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -859,7 +859,7 @@ def test_ptp(self): ser = Series(arr) print(np.ptp(ser), np.ptp(arr)) print(type(np.ptp(ser)), type(np.ptp(arr))) - assert np.ptp(ser) == np.ptp(arr) + assert np.ptp(ser.to_numpy()) == np.ptp(arr) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"])