Skip to content

BUG: DataFrame.corrwith raising for pyarrow-backed dtypes #52314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion pandas/core/internals/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 11 additions & 1 deletion pandas/tests/frame/methods/test_cov_corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down