Skip to content

BUG: Series.dot for arrow and nullable dtypes returns object-dtyped series #61376

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
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/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ Numeric
^^^^^^^
- Bug in :meth:`DataFrame.corr` where numerical precision errors resulted in correlations above ``1.0`` (:issue:`61120`)
- Bug in :meth:`DataFrame.quantile` where the column type was not preserved when ``numeric_only=True`` with a list-like ``q`` produced an empty result (:issue:`59035`)
- Bug in :meth:`Series.dot` returning ``object`` dtype for :class:`ArrowDtype` and nullable-dtype data (:issue:`61375`)
- Bug in ``np.matmul`` with :class:`Index` inputs raising a ``TypeError`` (:issue:`57079`)

Conversion
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2951,8 +2951,9 @@ def dot(self, other: AnyArrayLike | DataFrame) -> Series | np.ndarray:
)

if isinstance(other, ABCDataFrame):
common_type = find_common_type([self.dtypes] + list(other.dtypes))
return self._constructor(
np.dot(lvals, rvals), index=other.columns, copy=False
np.dot(lvals, rvals), index=other.columns, copy=False, dtype=common_type
).__finalize__(self, method="dot")
elif isinstance(other, Series):
return np.dot(lvals, rvals)
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/frame/methods/test_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,19 @@ def test_arrow_dtype(dtype, exp_dtype):
expected = DataFrame([[1, 2], [3, 4], [5, 6]], dtype=exp_dtype)

tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"dtype,exp_dtype",
[("Float32", "Float64"), ("Int16", "Int32"), ("float[pyarrow]", "double[pyarrow]")],
)
def test_arrow_dtype_series(dtype, exp_dtype):
pytest.importorskip("pyarrow")

cols = ["a", "b"]
series_a = Series([1, 2], index=cols, dtype="int32")
df_b = DataFrame([[1, 0], [0, 1]], index=cols, dtype=dtype)
result = series_a.dot(df_b)
expected = Series([1, 2], dtype=exp_dtype)

tm.assert_series_equal(result, expected)
Loading