From 2e1174fb2b91701db995ca7ef28ed7ac5c2595b6 Mon Sep 17 00:00:00 2001 From: Luke Manley Date: Thu, 30 Mar 2023 20:07:50 -0400 Subject: [PATCH 1/2] BUG: DataFrame.corrwith raising for pyarrow-backed dtypes --- pandas/core/internals/ops.py | 9 ++++++++- pandas/tests/frame/methods/test_cov_corr.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pandas/core/internals/ops.py b/pandas/core/internals/ops.py index 2b2cc1bb57b22..8434ed05571b7 100644 --- a/pandas/core/internals/ops.py +++ b/pandas/core/internals/ops.py @@ -6,6 +6,8 @@ NamedTuple, ) +from pandas.core.dtypes.common import is_1d_only_ea_dtype + if TYPE_CHECKING: from pandas._libs.internals import BlockPlacement from pandas._typing import ArrayLike @@ -60,7 +62,12 @@ def operate_blockwise( res_blks: list[Block] = [] for lvals, rvals, locs, left_ea, right_ea, rblk in _iter_block_pairs(left, right): res_values = array_op(lvals, rvals) - if left_ea and not right_ea and hasattr(res_values, "reshape"): + if ( + left_ea + and not right_ea + and hasattr(res_values, "reshape") + and not is_1d_only_ea_dtype(res_values.dtype) + ): res_values = res_values.reshape(1, -1) nbs = rblk._split_op_result(res_values) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 250b07f8248ef..d7734bca9e409 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -274,7 +274,17 @@ def test_corr_numeric_only(self, meth, numeric_only): class TestDataFrameCorrWith: - def test_corrwith(self, datetime_frame): + @pytest.mark.parametrize( + "dtype", + [ + "float64", + "Float64", + pytest.param("float64[pyarrow]", marks=td.skip_if_no("pyarrow")), + ], + ) + def test_corrwith(self, datetime_frame, dtype): + datetime_frame = datetime_frame.astype(dtype) + a = datetime_frame noise = Series(np.random.randn(len(a)), index=a.index) From 749c20f5de71075d72d16ca191a05e9310023041 Mon Sep 17 00:00:00 2001 From: Luke Manley Date: Thu, 30 Mar 2023 20:10:12 -0400 Subject: [PATCH 2/2] whatsnew --- 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 3a749708fb526..61e3bae2b4727 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -181,6 +181,7 @@ Timezones Numeric ^^^^^^^ - Bug in :meth:`Series.corr` and :meth:`Series.cov` raising ``AttributeError`` for masked dtypes (:issue:`51422`) +- Bug in :meth:`DataFrame.corrwith` raising ``NotImplementedError`` for pyarrow-backed dtypes (:issue:`52314`) - Conversion