Skip to content

BUG: Fix GroupBy aggregate coersion of outputs inconsistency for pyarrow dtypes #61640

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def floordiv_compat(
ArrayLike,
AxisInt,
Dtype,
DtypeObj,
FillnaOptions,
InterpolateOptions,
Iterator,
Expand Down Expand Up @@ -313,6 +314,18 @@ def __init__(self, values: pa.Array | pa.ChunkedArray) -> None:
)
self._dtype = ArrowDtype(self._pa_array.type)

@classmethod
def _from_scalars(cls, scalars, dtype: DtypeObj) -> Self:
try:
pa_array = cls._from_sequence(scalars, dtype=dtype)
except pa.ArrowNotImplementedError:
# _from_scalars should only raise ValueError or TypeError.
raise ValueError

if lib.infer_dtype(scalars, skipna=True) != lib.infer_dtype(pa_array, skipna=True):
raise ValueError
return pa_array

@classmethod
def _from_sequence(
cls, scalars, *, dtype: Dtype | None = None, copy: bool = False
Expand Down
7 changes: 7 additions & 0 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from pandas._typing import (
ArrayLike,
Dtype,
DtypeObj,
NpDtype,
Self,
npt,
Expand Down Expand Up @@ -180,6 +181,12 @@ def __len__(self) -> int:
"""
return len(self._pa_array)

@classmethod
def _from_scalars(cls, scalars, dtype: DtypeObj) -> Self:
if lib.infer_dtype(scalars, skipna=True) not in ["string", "empty"]:
raise ValueError
return cls._from_sequence(scalars, dtype=dtype)

@classmethod
def _from_sequence(
cls, scalars, *, dtype: Dtype | None = None, copy: bool = False
Expand Down
Loading