From c5ce23efcaa9c5f24fb97f7df07cb856e6dee1a7 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sat, 6 Apr 2024 23:44:46 +0800 Subject: [PATCH 01/16] add numeric only to df --- pandas/core/frame.py | 21 +++++++++++++-------- pandas/core/generic.py | 2 ++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 66a68755a2a09..b980ef684a83d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -12029,20 +12029,25 @@ def kurt( product = prod @doc(make_doc("cummin", ndim=2)) - def cummin(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: - return NDFrame.cummin(self, axis, skipna, *args, **kwargs) + def cummin(self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False, *args, **kwargs) -> Self: + data = self._get_numeric_data() if numeric_only else self + return NDFrame.cummin(data, axis, skipna, *args, **kwargs) @doc(make_doc("cummax", ndim=2)) - def cummax(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: - return NDFrame.cummax(self, axis, skipna, *args, **kwargs) + def cummax(self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False, *args, **kwargs) -> Self: + data = self._get_numeric_data() if numeric_only else self + return NDFrame.cummax(data, axis, skipna, *args, **kwargs) @doc(make_doc("cumsum", ndim=2)) - def cumsum(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: - return NDFrame.cumsum(self, axis, skipna, *args, **kwargs) + def cumsum(self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False, *args, **kwargs) -> Self: + data = self._get_numeric_data() if numeric_only else self + return NDFrame.cumsum(data, axis, skipna, *args, **kwargs) @doc(make_doc("cumprod", 2)) - def cumprod(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: - return NDFrame.cumprod(self, axis, skipna, *args, **kwargs) + def cumprod(self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False, *args, **kwargs) -> Self: + data = self._get_numeric_data() if numeric_only else self + return NDFrame.cumprod(data, axis, skipna, *args, **kwargs) + def nunique(self, axis: Axis = 0, dropna: bool = True) -> Series: """ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 99462917599e1..8a5901ff8c6a1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11939,6 +11939,8 @@ def last_valid_index(self) -> Hashable: skipna : bool, default True Exclude NA/null values. If an entire row/column is NA, the result will be NA. +numeric_only : bool, default False + Include only float, int, boolean columns. *args, **kwargs Additional keywords have no effect but might be accepted for compatibility with NumPy. From 1a8ca8485d2fcfacca4b944a05e885d777b48231 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 7 Apr 2024 00:39:05 +0800 Subject: [PATCH 02/16] docs --- doc/source/whatsnew/v2.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 495c8244142f9..0f78b18b20b05 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -276,6 +276,7 @@ Other enhancements - Added support for the DataFrame Consortium Standard (:issue:`54383`) - Performance improvement in :meth:`.DataFrameGroupBy.quantile` and :meth:`.SeriesGroupBy.quantile` (:issue:`51722`) - PyArrow-backed integer dtypes now support bitwise operations (:issue:`54495`) +- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_210.api_breaking: From 8d9181e4bc6d8b6520fecf1cfeccaf93b79a699b Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 7 Apr 2024 00:50:44 +0800 Subject: [PATCH 03/16] docs --- pandas/core/frame.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b980ef684a83d..66a68755a2a09 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -12029,25 +12029,20 @@ def kurt( product = prod @doc(make_doc("cummin", ndim=2)) - def cummin(self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False, *args, **kwargs) -> Self: - data = self._get_numeric_data() if numeric_only else self - return NDFrame.cummin(data, axis, skipna, *args, **kwargs) + def cummin(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: + return NDFrame.cummin(self, axis, skipna, *args, **kwargs) @doc(make_doc("cummax", ndim=2)) - def cummax(self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False, *args, **kwargs) -> Self: - data = self._get_numeric_data() if numeric_only else self - return NDFrame.cummax(data, axis, skipna, *args, **kwargs) + def cummax(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: + return NDFrame.cummax(self, axis, skipna, *args, **kwargs) @doc(make_doc("cumsum", ndim=2)) - def cumsum(self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False, *args, **kwargs) -> Self: - data = self._get_numeric_data() if numeric_only else self - return NDFrame.cumsum(data, axis, skipna, *args, **kwargs) + def cumsum(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: + return NDFrame.cumsum(self, axis, skipna, *args, **kwargs) @doc(make_doc("cumprod", 2)) - def cumprod(self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False, *args, **kwargs) -> Self: - data = self._get_numeric_data() if numeric_only else self - return NDFrame.cumprod(data, axis, skipna, *args, **kwargs) - + def cumprod(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: + return NDFrame.cumprod(self, axis, skipna, *args, **kwargs) def nunique(self, axis: Axis = 0, dropna: bool = True) -> Series: """ From 81744dcf594f7b8efc12c993f56f28ff29313409 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 7 Apr 2024 01:12:38 +0800 Subject: [PATCH 04/16] docs --- 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 0f78b18b20b05..906207b91b71d 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -270,13 +270,13 @@ Other enhancements - Improved error message when :meth:`.DataFrameGroupBy.agg` failed (:issue:`52930`) - Many read/to_* functions, such as :meth:`DataFrame.to_pickle` and :func:`read_csv`, support forwarding compression arguments to ``lzma.LZMAFile`` (:issue:`52979`) - Reductions :meth:`Series.argmax`, :meth:`Series.argmin`, :meth:`Series.idxmax`, :meth:`Series.idxmin`, :meth:`Index.argmax`, :meth:`Index.argmin`, :meth:`DataFrame.idxmax`, :meth:`DataFrame.idxmin` are now supported for object-dtype (:issue:`4279`, :issue:`18021`, :issue:`40685`, :issue:`43697`) +- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.to_parquet` and :func:`read_parquet` will now write and read ``attrs`` respectively (:issue:`54346`) - :meth:`Index.all` and :meth:`Index.any` with floating dtypes and timedelta64 dtypes no longer raise ``TypeError``, matching the :meth:`Series.all` and :meth:`Series.any` behavior (:issue:`54566`) - :meth:`Series.cummax`, :meth:`Series.cummin` and :meth:`Series.cumprod` are now supported for pyarrow dtypes with pyarrow version 13.0 and above (:issue:`52085`) - Added support for the DataFrame Consortium Standard (:issue:`54383`) - Performance improvement in :meth:`.DataFrameGroupBy.quantile` and :meth:`.SeriesGroupBy.quantile` (:issue:`51722`) - PyArrow-backed integer dtypes now support bitwise operations (:issue:`54495`) -- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_210.api_breaking: From ebdf2277c8df5780672f4f2a19fff8ed70efe401 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 7 Apr 2024 01:32:13 +0800 Subject: [PATCH 05/16] docs --- pandas/core/frame.py | 48 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 66a68755a2a09..d6f4e5ea25fc9 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -12029,20 +12029,52 @@ def kurt( product = prod @doc(make_doc("cummin", ndim=2)) - def cummin(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: - return NDFrame.cummin(self, axis, skipna, *args, **kwargs) + def cummin( + self, + axis: Axis = 0, + skipna: bool = True, + numeric_only: bool = False, + *args, + **kwargs, + ) -> Self: + data = self._get_numeric_data() if numeric_only else self + return NDFrame.cummin(data, axis, skipna, *args, **kwargs) @doc(make_doc("cummax", ndim=2)) - def cummax(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: - return NDFrame.cummax(self, axis, skipna, *args, **kwargs) + def cummax( + self, + axis: Axis = 0, + skipna: bool = True, + numeric_only: bool = False, + *args, + **kwargs, + ) -> Self: + data = self._get_numeric_data() if numeric_only else self + return NDFrame.cummax(data, axis, skipna, *args, **kwargs) @doc(make_doc("cumsum", ndim=2)) - def cumsum(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: - return NDFrame.cumsum(self, axis, skipna, *args, **kwargs) + def cumsum( + self, + axis: Axis = 0, + skipna: bool = True, + numeric_only: bool = False, + *args, + **kwargs, + ) -> Self: + data = self._get_numeric_data() if numeric_only else self + return NDFrame.cumsum(data, axis, skipna, *args, **kwargs) @doc(make_doc("cumprod", 2)) - def cumprod(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: - return NDFrame.cumprod(self, axis, skipna, *args, **kwargs) + def cumprod( + self, + axis: Axis = 0, + skipna: bool = True, + numeric_only: bool = False, + *args, + **kwargs, + ) -> Self: + data = self._get_numeric_data() if numeric_only else self + return NDFrame.cumprod(data, axis, skipna, *args, **kwargs) def nunique(self, axis: Axis = 0, dropna: bool = True) -> Series: """ From cc6053dc3b0c38790dc490f5a7d447267c68fe12 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 7 Apr 2024 02:28:31 +0800 Subject: [PATCH 06/16] docs --- pandas/tests/groupby/test_api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/tests/groupby/test_api.py b/pandas/tests/groupby/test_api.py index b5fdf058d1ab0..d2cfa530e7c65 100644 --- a/pandas/tests/groupby/test_api.py +++ b/pandas/tests/groupby/test_api.py @@ -183,10 +183,9 @@ def test_frame_consistency(groupby_func): elif groupby_func in ("bfill", "ffill"): exclude_expected = {"inplace", "axis", "limit_area"} elif groupby_func in ("cummax", "cummin"): - exclude_expected = {"skipna", "args"} - exclude_result = {"numeric_only"} + exclude_expected = {"axis", "skipna", "args"} elif groupby_func in ("cumprod", "cumsum"): - exclude_expected = {"skipna"} + exclude_expected = {"axis", "skipna", "numeric_only"} elif groupby_func in ("pct_change",): exclude_expected = {"kwargs"} elif groupby_func in ("rank",): From 176fff1f4906cba087a649b290b51cf83cb9109d Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 7 Apr 2024 11:48:20 +0800 Subject: [PATCH 07/16] add test --- pandas/core/generic.py | 62 ++++++++++++++++++++++++--- pandas/tests/frame/test_cumulative.py | 24 +++++++++++ 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8a5901ff8c6a1..38e5faf7935d5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11925,7 +11925,7 @@ def last_valid_index(self) -> Hashable: DataFrame.any : Return True if one (or more) elements are True. """ -_cnum_doc = """ +_cnum_pd_doc = """ Return cumulative {desc} over a DataFrame or Series axis. Returns a DataFrame or Series of the same size containing the cumulative @@ -11963,6 +11963,42 @@ def last_valid_index(self) -> Hashable: {examples}""" +_cnum_series_doc = """ +Return cumulative {desc} over a DataFrame or Series axis. + +Returns a DataFrame or Series of the same size containing the cumulative +{desc}. + +Parameters +---------- +axis : {{0 or 'index', 1 or 'columns'}}, default 0 + The index or the name of the axis. 0 is equivalent to None or 'index'. + For `Series` this parameter is unused and defaults to 0. +skipna : bool, default True + Exclude NA/null values. If an entire row/column is NA, the result + will be NA. +*args, **kwargs + Additional keywords have no effect but might be accepted for + compatibility with NumPy. + +Returns +------- +{name1} or {name2} + Return cumulative {desc} of {name1} or {name2}. + +See Also +-------- +core.window.expanding.Expanding.{accum_func_name} : Similar functionality + but ignores ``NaN`` values. +{name2}.{accum_func_name} : Return the {desc} over + {name2} axis. +{name2}.cummax : Return cumulative maximum over {name2} axis. +{name2}.cummin : Return cumulative minimum over {name2} axis. +{name2}.cumsum : Return cumulative sum over {name2} axis. +{name2}.cumprod : Return cumulative product over {name2} axis. + +{examples}""" + _cummin_examples = """\ Examples -------- @@ -12718,28 +12754,44 @@ def make_doc(name: str, ndim: int) -> str: kwargs = {"min_count": ""} elif name == "cumsum": - base_doc = _cnum_doc + if ndim == 1: + base_doc = _cnum_series_doc + else: + base_doc = _cnum_pd_doc + desc = "sum" see_also = "" examples = _cumsum_examples kwargs = {"accum_func_name": "sum"} elif name == "cumprod": - base_doc = _cnum_doc + if ndim == 1: + base_doc = _cnum_series_doc + else: + base_doc = _cnum_pd_doc + desc = "product" see_also = "" examples = _cumprod_examples kwargs = {"accum_func_name": "prod"} elif name == "cummin": - base_doc = _cnum_doc + if ndim == 1: + base_doc = _cnum_series_doc + else: + base_doc = _cnum_pd_doc + desc = "minimum" see_also = "" examples = _cummin_examples kwargs = {"accum_func_name": "min"} elif name == "cummax": - base_doc = _cnum_doc + if ndim == 1: + base_doc = _cnum_series_doc + else: + base_doc = _cnum_pd_doc + desc = "maximum" see_also = "" examples = _cummax_examples diff --git a/pandas/tests/frame/test_cumulative.py b/pandas/tests/frame/test_cumulative.py index d7aad680d389e..52aa8d0b5161a 100644 --- a/pandas/tests/frame/test_cumulative.py +++ b/pandas/tests/frame/test_cumulative.py @@ -7,10 +7,12 @@ """ import numpy as np +import pytest from pandas import ( DataFrame, Series, + Timestamp, ) import pandas._testing as tm @@ -81,3 +83,25 @@ def test_cumsum_preserve_dtypes(self): } ) tm.assert_frame_equal(result, expected) + + @pytest.mark.parametrize("method", ["cumsum", "cumprod", "cummin", "cummax"]) + def test_numeric_only_flag(self, method): + df = DataFrame( + { + "int": [1, 2, 3], + "bool": [True, False, False], + "string": ["a", "b", "c"], + "float": [1.0, 3.5, 4.0], + "datetime": [ + Timestamp(2018, 1, 1), + Timestamp(2019, 1, 1), + Timestamp(2020, 1, 1), + ], + } + ) + df_numeric_only = df.drop(["string", "datetime"], axis=1) + + for axis in [0, 1]: + result = getattr(df, method)(axis=axis, numeric_only=True) + expected = getattr(df_numeric_only, method)(axis) + tm.assert_frame_equal(result, expected) From 332229b3a822452ff258026ff09cf6fc6d6c73d8 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 7 Apr 2024 12:29:54 +0800 Subject: [PATCH 08/16] add test --- doc/source/whatsnew/v2.1.0.rst | 1 - doc/source/whatsnew/v2.2.2.rst | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 906207b91b71d..495c8244142f9 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -270,7 +270,6 @@ Other enhancements - Improved error message when :meth:`.DataFrameGroupBy.agg` failed (:issue:`52930`) - Many read/to_* functions, such as :meth:`DataFrame.to_pickle` and :func:`read_csv`, support forwarding compression arguments to ``lzma.LZMAFile`` (:issue:`52979`) - Reductions :meth:`Series.argmax`, :meth:`Series.argmin`, :meth:`Series.idxmax`, :meth:`Series.idxmin`, :meth:`Index.argmax`, :meth:`Index.argmin`, :meth:`DataFrame.idxmax`, :meth:`DataFrame.idxmin` are now supported for object-dtype (:issue:`4279`, :issue:`18021`, :issue:`40685`, :issue:`43697`) -- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.to_parquet` and :func:`read_parquet` will now write and read ``attrs`` respectively (:issue:`54346`) - :meth:`Index.all` and :meth:`Index.any` with floating dtypes and timedelta64 dtypes no longer raise ``TypeError``, matching the :meth:`Series.all` and :meth:`Series.any` behavior (:issue:`54566`) - :meth:`Series.cummax`, :meth:`Series.cummin` and :meth:`Series.cumprod` are now supported for pyarrow dtypes with pyarrow version 13.0 and above (:issue:`52085`) diff --git a/doc/source/whatsnew/v2.2.2.rst b/doc/source/whatsnew/v2.2.2.rst index 0dac3660c76b2..5b508f3f149e4 100644 --- a/doc/source/whatsnew/v2.2.2.rst +++ b/doc/source/whatsnew/v2.2.2.rst @@ -33,7 +33,7 @@ Bug fixes Other ~~~~~ -- +- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_222.contributors: From 24817481e20f1c80cfc0db7d743ab064e9eb0501 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 7 Apr 2024 15:10:10 +0800 Subject: [PATCH 09/16] add test --- doc/source/whatsnew/v2.2.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.2.2.rst b/doc/source/whatsnew/v2.2.2.rst index 5b508f3f149e4..f2aae59525be7 100644 --- a/doc/source/whatsnew/v2.2.2.rst +++ b/doc/source/whatsnew/v2.2.2.rst @@ -33,7 +33,7 @@ Bug fixes Other ~~~~~ -- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) +- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_222.contributors: From ad521c67d2cc22de3b5b6d702a4c504832b7b896 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 7 Apr 2024 15:10:27 +0800 Subject: [PATCH 10/16] add test --- doc/source/whatsnew/v2.2.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.2.2.rst b/doc/source/whatsnew/v2.2.2.rst index f2aae59525be7..5b508f3f149e4 100644 --- a/doc/source/whatsnew/v2.2.2.rst +++ b/doc/source/whatsnew/v2.2.2.rst @@ -33,7 +33,7 @@ Bug fixes Other ~~~~~ -- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) +- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_222.contributors: From 1bf9706772e9f5bc7ea406c72b4e0e0c0e800087 Mon Sep 17 00:00:00 2001 From: weikhor Date: Thu, 11 Apr 2024 00:46:45 +0800 Subject: [PATCH 11/16] resolve conversation --- doc/source/whatsnew/v2.2.2.rst | 2 +- doc/source/whatsnew/v3.0.0.rst | 2 +- pandas/tests/frame/test_cumulative.py | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v2.2.2.rst b/doc/source/whatsnew/v2.2.2.rst index 5b508f3f149e4..0dac3660c76b2 100644 --- a/doc/source/whatsnew/v2.2.2.rst +++ b/doc/source/whatsnew/v2.2.2.rst @@ -33,7 +33,7 @@ Bug fixes Other ~~~~~ -- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) +- .. --------------------------------------------------------------------------- .. _whatsnew_222.contributors: diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 19b448a1871c2..27435230b834f 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -35,7 +35,7 @@ Other enhancements - Support passing a :class:`Series` input to :func:`json_normalize` that retains the :class:`Series` :class:`Index` (:issue:`51452`) - Users can globally disable any ``PerformanceWarning`` by setting the option ``mode.performance_warnings`` to ``False`` (:issue:`56920`) - :meth:`Styler.format_index_names` can now be used to format the index and column names (:issue:`48936` and :issue:`47489`) -- +- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: diff --git a/pandas/tests/frame/test_cumulative.py b/pandas/tests/frame/test_cumulative.py index 52aa8d0b5161a..fb7b1241b0386 100644 --- a/pandas/tests/frame/test_cumulative.py +++ b/pandas/tests/frame/test_cumulative.py @@ -85,7 +85,9 @@ def test_cumsum_preserve_dtypes(self): tm.assert_frame_equal(result, expected) @pytest.mark.parametrize("method", ["cumsum", "cumprod", "cummin", "cummax"]) - def test_numeric_only_flag(self, method): + @pytest.mark.parametrize("axis", [0, 1]) + def test_numeric_only_flag(self, method, axis): + print(method, axis) df = DataFrame( { "int": [1, 2, 3], @@ -99,7 +101,7 @@ def test_numeric_only_flag(self, method): ], } ) - df_numeric_only = df.drop(["string", "datetime"], axis=1) + df_numeric_only = df.drop(["string", "datetime"], axis=axis) for axis in [0, 1]: result = getattr(df, method)(axis=axis, numeric_only=True) From f7f3f49bd6473b662db10b462c46d97ecc02a0a8 Mon Sep 17 00:00:00 2001 From: weikhor Date: Thu, 11 Apr 2024 00:48:16 +0800 Subject: [PATCH 12/16] resolve conversation --- pandas/tests/frame/test_cumulative.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/tests/frame/test_cumulative.py b/pandas/tests/frame/test_cumulative.py index fb7b1241b0386..ab217e1b1332a 100644 --- a/pandas/tests/frame/test_cumulative.py +++ b/pandas/tests/frame/test_cumulative.py @@ -87,7 +87,6 @@ def test_cumsum_preserve_dtypes(self): @pytest.mark.parametrize("method", ["cumsum", "cumprod", "cummin", "cummax"]) @pytest.mark.parametrize("axis", [0, 1]) def test_numeric_only_flag(self, method, axis): - print(method, axis) df = DataFrame( { "int": [1, 2, 3], @@ -101,9 +100,8 @@ def test_numeric_only_flag(self, method, axis): ], } ) - df_numeric_only = df.drop(["string", "datetime"], axis=axis) + df_numeric_only = df.drop(["string", "datetime"], axis=1) - for axis in [0, 1]: - result = getattr(df, method)(axis=axis, numeric_only=True) - expected = getattr(df_numeric_only, method)(axis) - tm.assert_frame_equal(result, expected) + result = getattr(df, method)(axis=axis, numeric_only=True) + expected = getattr(df_numeric_only, method)(axis) + tm.assert_frame_equal(result, expected) From 9b2b97ea1f37461f502e37260e451512aacaab0b Mon Sep 17 00:00:00 2001 From: weikhor Date: Thu, 11 Apr 2024 12:50:09 +0800 Subject: [PATCH 13/16] enhance oc --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 27435230b834f..b90cf308b90a1 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -35,7 +35,7 @@ Other enhancements - Support passing a :class:`Series` input to :func:`json_normalize` that retains the :class:`Series` :class:`Index` (:issue:`51452`) - Users can globally disable any ``PerformanceWarning`` by setting the option ``mode.performance_warnings`` to ``False`` (:issue:`56920`) - :meth:`Styler.format_index_names` can now be used to format the index and column names (:issue:`48936` and :issue:`47489`) -- :meth:`DataFrame.cum*` methods now have a ``numeric_only`` parameter (:issue:`53072`) +- :meth:`DataFrame.cummin` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From d1ce9d061e284afb1061261ad5fceab13c109b1c Mon Sep 17 00:00:00 2001 From: weikhor Date: Thu, 11 Apr 2024 12:50:21 +0800 Subject: [PATCH 14/16] enhance oc --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index b90cf308b90a1..bf40ac2aad629 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -35,7 +35,7 @@ Other enhancements - Support passing a :class:`Series` input to :func:`json_normalize` that retains the :class:`Series` :class:`Index` (:issue:`51452`) - Users can globally disable any ``PerformanceWarning`` by setting the option ``mode.performance_warnings`` to ``False`` (:issue:`56920`) - :meth:`Styler.format_index_names` can now be used to format the index and column names (:issue:`48936` and :issue:`47489`) -- :meth:`DataFrame.cummin` methods now have a ``numeric_only`` parameter (:issue:`53072`) +- :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From 2d8ba36f31ba4ccd2d97a8e2150be32065142a97 Mon Sep 17 00:00:00 2001 From: weikhor Date: Thu, 11 Apr 2024 12:50:31 +0800 Subject: [PATCH 15/16] enhance oc --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index bf40ac2aad629..48b29cd64bba1 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -35,7 +35,7 @@ Other enhancements - Support passing a :class:`Series` input to :func:`json_normalize` that retains the :class:`Series` :class:`Index` (:issue:`51452`) - Users can globally disable any ``PerformanceWarning`` by setting the option ``mode.performance_warnings`` to ``False`` (:issue:`56920`) - :meth:`Styler.format_index_names` can now be used to format the index and column names (:issue:`48936` and :issue:`47489`) -- :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax` methods now have a ``numeric_only`` parameter (:issue:`53072`) +- :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From 2e085f31b2e7fb720d77b3f83522405a39090e5b Mon Sep 17 00:00:00 2001 From: weikhor Date: Thu, 11 Apr 2024 12:50:42 +0800 Subject: [PATCH 16/16] enhance oc --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 48b29cd64bba1..d189c4f4bf248 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -35,7 +35,7 @@ Other enhancements - Support passing a :class:`Series` input to :func:`json_normalize` that retains the :class:`Series` :class:`Index` (:issue:`51452`) - Users can globally disable any ``PerformanceWarning`` by setting the option ``mode.performance_warnings`` to ``False`` (:issue:`56920`) - :meth:`Styler.format_index_names` can now be used to format the index and column names (:issue:`48936` and :issue:`47489`) -- :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` methods now have a ``numeric_only`` parameter (:issue:`53072`) +- :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: