Skip to content

Commit 1322e72

Browse files
fangchenliclaude
andcommitted
TYP: fix mypy errors in _groupby_op_pyarrow
- Add type annotation for aggs list to handle mixed tuple types - Rename result to fallback_result to avoid type conflict 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 0b55c93 commit 1322e72

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,9 @@ def _groupby_op_pyarrow(
26632663

26642664
if how in ["std", "var", "sem"]:
26652665
ddof = kwargs.get("ddof", 1)
2666-
aggs = [("value", pa_agg_func, pc.VarianceOptions(ddof=ddof))]
2666+
aggs: list[tuple[str, str] | tuple[str, str, pc.VarianceOptions]] = [
2667+
("value", pa_agg_func, pc.VarianceOptions(ddof=ddof))
2668+
]
26672669
else:
26682670
aggs = [("value", pa_agg_func)]
26692671
aggs.append(("value", "count"))
@@ -2772,30 +2774,30 @@ def _groupby_op(
27722774
return result
27732775

27742776
# Fall back to converting to masked/datetime array and using Cython
2775-
values: ExtensionArray
2777+
fallback_values: ExtensionArray
27762778
if pa.types.is_timestamp(pa_type):
2777-
values = self._to_datetimearray()
2779+
fallback_values = self._to_datetimearray()
27782780
elif pa.types.is_duration(pa_type):
2779-
values = self._to_timedeltaarray()
2781+
fallback_values = self._to_timedeltaarray()
27802782
else:
2781-
values = self._to_masked()
2783+
fallback_values = self._to_masked()
27822784

2783-
result = values._groupby_op(
2785+
fallback_result = fallback_values._groupby_op(
27842786
how=how,
27852787
has_dropped_na=has_dropped_na,
27862788
min_count=min_count,
27872789
ngroups=ngroups,
27882790
ids=ids,
27892791
**kwargs,
27902792
)
2791-
if isinstance(result, np.ndarray):
2792-
return result
2793-
elif isinstance(result, BaseMaskedArray):
2794-
pa_result = result.__arrow_array__()
2793+
if isinstance(fallback_result, np.ndarray):
2794+
return fallback_result
2795+
elif isinstance(fallback_result, BaseMaskedArray):
2796+
pa_result = fallback_result.__arrow_array__()
27952797
return self._from_pyarrow_array(pa_result)
27962798
else:
27972799
# DatetimeArray, TimedeltaArray
2798-
pa_result = pa.array(result)
2800+
pa_result = pa.array(fallback_result)
27992801
return self._from_pyarrow_array(pa_result)
28002802

28012803
def _apply_elementwise(self, func: Callable) -> list[list[Any]]:

0 commit comments

Comments
 (0)