From 5436de108e00f2867d1873da370f297f18a000f8 Mon Sep 17 00:00:00 2001 From: weikhor Date: Fri, 12 Apr 2024 21:59:36 +0800 Subject: [PATCH 01/20] Testing --- doc/source/whatsnew/v3.0.0.rst | 2 +- pandas/core/frame.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index e05cc87d1af14..3e367a32d673a 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -36,8 +36,8 @@ Other enhancements - Support reading value labels from Stata 108-format (Stata 6) and earlier files (:issue:`58154`) - 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.corrwith()` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) - :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: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 0b386efb5a867..53b0515f0a4ca 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11091,6 +11091,7 @@ def corrwith( drop: bool = False, method: CorrelationMethod = "pearson", numeric_only: bool = False, + min_periods: int | None = None, ) -> Series: """ Compute pairwise correlation. @@ -11125,6 +11126,8 @@ def corrwith( .. versionchanged:: 2.0.0 The default value of ``numeric_only`` is now ``False``. + min_periods : int, optional + Minimum number of observations needed to have a valid result. Returns ------- @@ -11164,7 +11167,10 @@ def corrwith( this = self._get_numeric_data() if numeric_only else self if isinstance(other, Series): - return this.apply(lambda x: other.corr(x, method=method), axis=axis) + return this.apply( + lambda x: other.corr(x, method=method, min_period=min_periods), + axis=axis, + ) if numeric_only: other = other._get_numeric_data() From 2d14ef11a84cfe16967bbb88d2bc058fd0b1ac66 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sat, 13 Apr 2024 02:58:49 +0800 Subject: [PATCH 02/20] Testing --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 53b0515f0a4ca..6cebca73736cc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11168,7 +11168,7 @@ def corrwith( if isinstance(other, Series): return this.apply( - lambda x: other.corr(x, method=method, min_period=min_periods), + lambda x: other.corr(x, method=method, min_periods=min_periods), axis=axis, ) From bbd06cecfe104e85434081a949bca79533583dda Mon Sep 17 00:00:00 2001 From: weikhor Date: Sat, 13 Apr 2024 03:31:47 +0800 Subject: [PATCH 03/20] enhance test case --- pandas/tests/frame/methods/test_cov_corr.py | 24 +++++++++++++++++++++ pandas/tests/groupby/test_api.py | 2 ++ 2 files changed, 26 insertions(+) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 4d2d83d25e8da..3fb7bd9a12e9c 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -461,3 +461,27 @@ def test_corrwith_spearman_with_tied_data(self): result = df_bool.corrwith(ser_bool) expected = Series([0.57735, 0.57735], index=["A", "B"]) tm.assert_series_equal(result, expected) + + def test_corrwith_min_periods(self): + # GH#9490 + df1 = DataFrame( + { + "A": [1, np.nan, 7, 8], + "B": [False, True, True, False], + "C": [10, 4, 9, 3], + } + ) + df2 = df1[["B", "C"]] + result = (df1 + 1).corrwith(df2.B, method="spearman", min_periods=2) + expected = Series([0.0, 1.0, 0.0], index=["A", "B", "C"]) + tm.assert_series_equal(result, expected) + + df_bool = DataFrame( + {"A": [True, True, False, False], "B": [True, False, False, True]} + ) + ser_bool = Series([True, True, False, True]) + result = df_bool.corrwith(ser_bool, min_periods=3) + expected = Series( + [0.57735, 0.57735], index=["A", "B"] + ) # Expected values based on min_periods + tm.assert_series_equal(result, expected) diff --git a/pandas/tests/groupby/test_api.py b/pandas/tests/groupby/test_api.py index d2cfa530e7c65..33b39bad4ab81 100644 --- a/pandas/tests/groupby/test_api.py +++ b/pandas/tests/groupby/test_api.py @@ -192,6 +192,8 @@ def test_frame_consistency(groupby_func): exclude_expected = {"numeric_only"} elif groupby_func in ("quantile",): exclude_expected = {"method", "axis"} + elif groupby_func in ["corrwith"]: + exclude_expected = {"min_periods"} if groupby_func not in ["pct_change", "size"]: exclude_expected |= {"axis"} From e6d53477eee813fcf5bc5f2f2575f184b082a61e Mon Sep 17 00:00:00 2001 From: weikhor Date: Sat, 13 Apr 2024 11:40:26 +0800 Subject: [PATCH 04/20] add test --- pandas/tests/frame/methods/test_cov_corr.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 3fb7bd9a12e9c..c2845f099d3ae 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -464,6 +464,7 @@ def test_corrwith_spearman_with_tied_data(self): def test_corrwith_min_periods(self): # GH#9490 + pytest.importorskip("scipy") df1 = DataFrame( { "A": [1, np.nan, 7, 8], From 64957c025ddbcb00bcb8280806ab31471ae7e962 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sat, 13 Apr 2024 13:00:21 +0800 Subject: [PATCH 05/20] testing --- 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 2396d245a6da3..7657c6763466d 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -36,7 +36,7 @@ Other enhancements - Support reading value labels from Stata 108-format (Stata 6) and earlier files (:issue:`58154`) - 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.corrwith()` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) +- :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) - :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: From b2f92dd683786b2eb62582dec82183e4c291290d Mon Sep 17 00:00:00 2001 From: weikhor Date: Sat, 13 Apr 2024 16:05:22 +0800 Subject: [PATCH 06/20] add --- pandas/core/frame.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6cebca73736cc..cbd71c2ecf3f4 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11126,8 +11126,6 @@ def corrwith( .. versionchanged:: 2.0.0 The default value of ``numeric_only`` is now ``False``. - min_periods : int, optional - Minimum number of observations needed to have a valid result. Returns ------- From 906d49dca10465d5ffec701419d8393530d6b248 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sat, 13 Apr 2024 16:32:46 +0800 Subject: [PATCH 07/20] add test --- doc/source/whatsnew/v3.0.0.rst | 1 - pandas/core/frame.py | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 7657c6763466d..426f67a1a4495 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -36,7 +36,6 @@ Other enhancements - Support reading value labels from Stata 108-format (Stata 6) and earlier files (:issue:`58154`) - 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.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) - :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: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index cbd71c2ecf3f4..6cebca73736cc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11126,6 +11126,8 @@ def corrwith( .. versionchanged:: 2.0.0 The default value of ``numeric_only`` is now ``False``. + min_periods : int, optional + Minimum number of observations needed to have a valid result. Returns ------- From 60ffadde7d4e6950fa648ac75d8f2c7b1d01bc87 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 21 Apr 2024 21:30:14 +0800 Subject: [PATCH 08/20] enhance --- doc/source/whatsnew/v3.0.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 39b73565dd380..e0107c515268d 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -38,8 +38,9 @@ Other enhancements - 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`) - :class:`.errors.DtypeWarning` improved to include column names when mixed data types are detected (:issue:`58174`) -- :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) - :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) +- :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) +- .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From 547cd9d9608a372afd406c1fdac997f014d14d0a Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 21 Apr 2024 21:36:19 +0800 Subject: [PATCH 09/20] add --- doc/source/whatsnew/v3.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index e0107c515268d..0f62b4a29a12b 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -40,6 +40,7 @@ Other enhancements - :class:`.errors.DtypeWarning` improved to include column names when mixed data types are detected (:issue:`58174`) - :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) +- :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) - .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From cf47fbe25b903d9bda7a6e65599cb0c86844aaa9 Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 21 Apr 2024 21:37:33 +0800 Subject: [PATCH 10/20] add --- doc/source/whatsnew/v3.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 0f62b4a29a12b..9292e1d5b25ce 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -41,7 +41,6 @@ Other enhancements - :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) - :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) -- .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From e1172249ad40edb1bbbaafe9ba29ce4e338b72ea Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 21 Apr 2024 21:37:46 +0800 Subject: [PATCH 11/20] add --- doc/source/whatsnew/v3.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 9292e1d5b25ce..0f62b4a29a12b 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -41,6 +41,7 @@ Other enhancements - :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) - :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) +- .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From f665ee13e1e94e1d09e5666d78614eb02c2ac2dc Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 21 Apr 2024 21:40:04 +0800 Subject: [PATCH 12/20] add --- pandas/core/frame.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 38e9ef218d89d..f7a6a336a5fef 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11136,13 +11136,14 @@ def corrwith( numeric_only : bool, default False Include only `float`, `int` or `boolean` data. + + min_periods : int, optional + Minimum number of observations needed to have a valid result. .. versionadded:: 1.5.0 .. versionchanged:: 2.0.0 The default value of ``numeric_only`` is now ``False``. - min_periods : int, optional - Minimum number of observations needed to have a valid result. Returns ------- From f1f6040abcb55107a583dbf96829d79ae76a46bb Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 21 Apr 2024 23:20:23 +0800 Subject: [PATCH 13/20] add --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f7a6a336a5fef..e14d7842b5816 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11137,7 +11137,7 @@ def corrwith( numeric_only : bool, default False Include only `float`, `int` or `boolean` data. - min_periods : int, optional + min_periods : int, optional Minimum number of observations needed to have a valid result. .. versionadded:: 1.5.0 From 10d8274d41e8045742df7838c7255836975de82d Mon Sep 17 00:00:00 2001 From: weikhor Date: Sun, 21 Apr 2024 23:21:36 +0800 Subject: [PATCH 14/20] add --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e14d7842b5816..12f81c39510bc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11136,8 +11136,8 @@ def corrwith( numeric_only : bool, default False Include only `float`, `int` or `boolean` data. - - min_periods : int, optional + + min_periods : int, optional Minimum number of observations needed to have a valid result. .. versionadded:: 1.5.0 From 3fadb727f967299b706df5b5c2de013ce734f691 Mon Sep 17 00:00:00 2001 From: weikhor Date: Mon, 22 Apr 2024 00:32:38 +0800 Subject: [PATCH 15/20] enhance --- doc/source/whatsnew/v3.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 0f62b4a29a12b..e0107c515268d 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -40,7 +40,6 @@ Other enhancements - :class:`.errors.DtypeWarning` improved to include column names when mixed data types are detected (:issue:`58174`) - :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) -- :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) - .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From 193515a3fb277004c747e759cd807de84631db73 Mon Sep 17 00:00:00 2001 From: weikhor Date: Mon, 22 Apr 2024 00:35:44 +0800 Subject: [PATCH 16/20] enhance --- 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 e0107c515268d..8618d7d525771 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -40,7 +40,7 @@ Other enhancements - :class:`.errors.DtypeWarning` improved to include column names when mixed data types are detected (:issue:`58174`) - :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) -- + .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From 5386e0ec116a49757ae0529b3d69ce6a88fda3f1 Mon Sep 17 00:00:00 2001 From: weikhor Date: Mon, 22 Apr 2024 00:36:45 +0800 Subject: [PATCH 17/20] enhance --- doc/source/whatsnew/v3.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 8618d7d525771..fe073e2cb069f 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -38,6 +38,7 @@ Other enhancements - 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`) - :class:`.errors.DtypeWarning` improved to include column names when mixed data types are detected (:issue:`58174`) +- :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) - :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) From 3cc9eb1980c992a84de6ba01d65a93e1c55dd845 Mon Sep 17 00:00:00 2001 From: Khor Chean Wei Date: Tue, 30 Apr 2024 17:31:02 +0800 Subject: [PATCH 18/20] Update doc/source/whatsnew/v3.0.0.rst Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- 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 d08230696b8b1..336634f8f358c 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -39,7 +39,7 @@ Other enhancements - 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`) - :class:`.errors.DtypeWarning` improved to include column names when mixed data types are detected (:issue:`58174`) -- :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`pd.Series.corr` (:issue:`9490`) +- :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`Series.corr` (:issue:`9490`) - :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) - :meth:`Series.cummin` and :meth:`Series.cummax` now supports :class:`CategoricalDtype` (:issue:`52335`) From ceb4d9a8a2378896f3f598dd615c3b5d0c388c30 Mon Sep 17 00:00:00 2001 From: weikhor Date: Tue, 30 Apr 2024 18:42:16 +0800 Subject: [PATCH 19/20] test --- pandas/tests/frame/methods/test_cov_corr.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index c2845f099d3ae..930f33745a3a4 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -462,9 +462,8 @@ def test_corrwith_spearman_with_tied_data(self): expected = Series([0.57735, 0.57735], index=["A", "B"]) tm.assert_series_equal(result, expected) - def test_corrwith_min_periods(self): + def test_corrwith_min_periods_method(self): # GH#9490 - pytest.importorskip("scipy") df1 = DataFrame( { "A": [1, np.nan, 7, 8], @@ -477,12 +476,12 @@ def test_corrwith_min_periods(self): expected = Series([0.0, 1.0, 0.0], index=["A", "B", "C"]) tm.assert_series_equal(result, expected) + def test_corrwith_min_periods_boolean(self): + # GH#9490 df_bool = DataFrame( {"A": [True, True, False, False], "B": [True, False, False, True]} ) ser_bool = Series([True, True, False, True]) result = df_bool.corrwith(ser_bool, min_periods=3) - expected = Series( - [0.57735, 0.57735], index=["A", "B"] - ) # Expected values based on min_periods + expected = Series([0.57735, 0.57735], index=["A", "B"]) tm.assert_series_equal(result, expected) From 2c8a258194b2a97fca0cdc18da8eaa5c9f680654 Mon Sep 17 00:00:00 2001 From: Khor Chean Wei Date: Wed, 1 May 2024 00:46:08 +0800 Subject: [PATCH 20/20] Update test_cov_corr.py --- pandas/tests/frame/methods/test_cov_corr.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 930f33745a3a4..53aa44f264c7a 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -464,6 +464,7 @@ def test_corrwith_spearman_with_tied_data(self): def test_corrwith_min_periods_method(self): # GH#9490 + pytest.importorskip("scipy") df1 = DataFrame( { "A": [1, np.nan, 7, 8],