Skip to content

Commit 75b647a

Browse files
authored
TYP: implement typing.Manager2D (#40853)
1 parent eea8043 commit 75b647a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

pandas/_typing.py

+3
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@
187187
# internals
188188
Manager = Union["ArrayManager", "BlockManager", "SingleBlockManager"]
189189
SingleManager = Union["SingleArrayManager", "SingleBlockManager"]
190+
Manager2D = Union["ArrayManager", "BlockManager"]
191+
# TODO: Manager2d excludes SingleBlockManager, but does not exclude
192+
# SingleArrayManager
190193

191194
# indexing
192195
# PositionalIndexer -> valid 1D positional indexer, e.g. can pass

pandas/core/groupby/generic.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
ArrayLike,
3737
FrameOrSeries,
3838
FrameOrSeriesUnion,
39-
Manager,
39+
Manager2D,
4040
)
4141
from pandas.util._decorators import (
4242
Appender,
@@ -177,6 +177,9 @@ def pinner(cls):
177177
class SeriesGroupBy(GroupBy[Series]):
178178
_apply_allowlist = base.series_apply_allowlist
179179

180+
# Defined as a cache_readonly in SelectionMixin
181+
_obj_with_exclusions: Series
182+
180183
def _iterate_slices(self) -> Iterable[Series]:
181184
yield self._selected_obj
182185

@@ -927,6 +930,9 @@ def pct_change(self, periods=1, fill_method="pad", limit=None, freq=None):
927930
@pin_allowlisted_properties(DataFrame, base.dataframe_apply_allowlist)
928931
class DataFrameGroupBy(GroupBy[DataFrame]):
929932

933+
# Defined as a cache_readonly in SelectionMixin
934+
_obj_with_exclusions: DataFrame
935+
930936
_apply_allowlist = base.dataframe_apply_allowlist
931937

932938
_agg_examples_doc = dedent(
@@ -1095,9 +1101,9 @@ def _cython_agg_general(
10951101

10961102
def _cython_agg_manager(
10971103
self, how: str, alt=None, numeric_only: bool = True, min_count: int = -1
1098-
) -> Manager:
1104+
) -> Manager2D:
10991105

1100-
data: Manager = self._get_data_to_aggregate()
1106+
data: Manager2D = self._get_data_to_aggregate()
11011107

11021108
if numeric_only:
11031109
data = data.get_numeric_data(copy=False)
@@ -1691,7 +1697,7 @@ def _wrap_frame_output(self, result, obj: DataFrame) -> DataFrame:
16911697
else:
16921698
return self.obj._constructor(result, index=obj.index, columns=result_index)
16931699

1694-
def _get_data_to_aggregate(self) -> Manager:
1700+
def _get_data_to_aggregate(self) -> Manager2D:
16951701
obj = self._obj_with_exclusions
16961702
if self.axis == 1:
16971703
return obj.T._mgr
@@ -1776,7 +1782,7 @@ def _wrap_transformed_output(
17761782

17771783
return result
17781784

1779-
def _wrap_agged_manager(self, mgr: Manager) -> DataFrame:
1785+
def _wrap_agged_manager(self, mgr: Manager2D) -> DataFrame:
17801786
if not self.as_index:
17811787
index = np.arange(mgr.shape[1])
17821788
mgr.set_axis(1, ibase.Index(index), verify_integrity=False)

0 commit comments

Comments
 (0)