Skip to content

Commit f77a0e6

Browse files
BUG: fixes Arrow Dataframes/Series producing a Numpy object result (#54025)
* fix dot dtype * missing pa fix * fix doc build issue * expand tests * fix win dtype * update * Update doc/source/whatsnew/v2.1.0.rst Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --------- Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
1 parent fa17d28 commit f77a0e6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

doc/source/whatsnew/v2.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ Numeric
467467
- Bug in :meth:`Series.mean`, :meth:`DataFrame.mean` with object-dtype values containing strings that can be converted to numbers (e.g. "2") returning incorrect numeric results; these now raise ``TypeError`` (:issue:`36703`, :issue:`44008`)
468468
- Bug in :meth:`DataFrame.corrwith` raising ``NotImplementedError`` for pyarrow-backed dtypes (:issue:`52314`)
469469
- Bug in :meth:`DataFrame.size` and :meth:`Series.size` returning 64-bit integer instead of int (:issue:`52897`)
470+
- Bug in :meth:`DateFrame.dot` returning ``object`` dtype for :class:`ArrowDtype` data (:issue:`53979`)
470471
- Bug in :meth:`Series.any`, :meth:`Series.all`, :meth:`DataFrame.any`, and :meth:`DataFrame.all` had the default value of ``bool_only`` set to ``None`` instead of ``False``; this change should have no impact on users (:issue:`53258`)
471472
- Bug in :meth:`Series.corr` and :meth:`Series.cov` raising ``AttributeError`` for masked dtypes (:issue:`51422`)
472473
- Bug in :meth:`Series.median` and :meth:`DataFrame.median` with object-dtype values containing strings that can be converted to numbers (e.g. "2") returning incorrect numeric results; these now raise ``TypeError`` (:issue:`34671`)

pandas/core/frame.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,15 +1620,18 @@ def dot(self, other: AnyArrayLike | DataFrame) -> DataFrame | Series:
16201620
)
16211621

16221622
if isinstance(other, DataFrame):
1623+
common_type = find_common_type(list(self.dtypes) + list(other.dtypes))
16231624
return self._constructor(
16241625
np.dot(lvals, rvals),
16251626
index=left.index,
16261627
columns=other.columns,
16271628
copy=False,
1629+
dtype=common_type,
16281630
)
16291631
elif isinstance(other, Series):
1632+
common_type = find_common_type(list(self.dtypes) + [other.dtypes])
16301633
return self._constructor_sliced(
1631-
np.dot(lvals, rvals), index=left.index, copy=False
1634+
np.dot(lvals, rvals), index=left.index, copy=False, dtype=common_type
16321635
)
16331636
elif isinstance(rvals, (np.ndarray, Index)):
16341637
result = np.dot(lvals, rvals)

pandas/tests/frame/methods/test_dot.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,19 @@ def reduced_dim_assert(cls, result, expected):
129129
"""
130130
tm.assert_series_equal(result, expected, check_names=False)
131131
assert result.name is None
132+
133+
134+
@pytest.mark.parametrize(
135+
"dtype,exp_dtype",
136+
[("Float32", "Float64"), ("Int16", "Int32"), ("float[pyarrow]", "double[pyarrow]")],
137+
)
138+
def test_arrow_dtype(dtype, exp_dtype):
139+
pytest.importorskip("pyarrow")
140+
141+
cols = ["a", "b"]
142+
df_a = DataFrame([[1, 2], [3, 4], [5, 6]], columns=cols, dtype="int32")
143+
df_b = DataFrame([[1, 0], [0, 1]], index=cols, dtype=dtype)
144+
result = df_a.dot(df_b)
145+
expected = DataFrame([[1, 2], [3, 4], [5, 6]], dtype=exp_dtype)
146+
147+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)