@@ -1092,9 +1092,8 @@ def result_to_bool(result: np.ndarray, inference: Type) -> np.ndarray:
1092
1092
1093
1093
return self ._get_cythonized_result (
1094
1094
"group_any_all" ,
1095
- self .grouper ,
1096
1095
aggregate = True ,
1097
- cython_dtype = np .uint8 ,
1096
+ cython_dtype = np .dtype ( np . uint8 ) ,
1098
1097
needs_values = True ,
1099
1098
needs_mask = True ,
1100
1099
pre_processing = objs_to_bool ,
@@ -1305,7 +1304,7 @@ def size(self):
1305
1304
result = self .grouper .size ()
1306
1305
1307
1306
if isinstance (self .obj , Series ):
1308
- result .name = getattr ( self .obj , " name" , None )
1307
+ result .name = self .obj . name
1309
1308
return result
1310
1309
1311
1310
@classmethod
@@ -1586,9 +1585,8 @@ def _fill(self, direction, limit=None):
1586
1585
1587
1586
return self ._get_cythonized_result (
1588
1587
"group_fillna_indexer" ,
1589
- self .grouper ,
1590
1588
needs_mask = True ,
1591
- cython_dtype = np .int64 ,
1589
+ cython_dtype = np .dtype ( np . int64 ) ,
1592
1590
result_is_index = True ,
1593
1591
direction = direction ,
1594
1592
limit = limit ,
@@ -1882,11 +1880,10 @@ def post_processor(vals: np.ndarray, inference: Optional[Type]) -> np.ndarray:
1882
1880
if is_scalar (q ):
1883
1881
return self ._get_cythonized_result (
1884
1882
"group_quantile" ,
1885
- self .grouper ,
1886
1883
aggregate = True ,
1887
1884
needs_values = True ,
1888
1885
needs_mask = True ,
1889
- cython_dtype = np .float64 ,
1886
+ cython_dtype = np .dtype ( np . float64 ) ,
1890
1887
pre_processing = pre_processor ,
1891
1888
post_processing = post_processor ,
1892
1889
q = q ,
@@ -1896,11 +1893,10 @@ def post_processor(vals: np.ndarray, inference: Optional[Type]) -> np.ndarray:
1896
1893
results = [
1897
1894
self ._get_cythonized_result (
1898
1895
"group_quantile" ,
1899
- self .grouper ,
1900
1896
aggregate = True ,
1901
1897
needs_values = True ,
1902
1898
needs_mask = True ,
1903
- cython_dtype = np .float64 ,
1899
+ cython_dtype = np .dtype ( np . float64 ) ,
1904
1900
pre_processing = pre_processor ,
1905
1901
post_processing = post_processor ,
1906
1902
q = qi ,
@@ -2167,14 +2163,13 @@ def cummax(self, axis=0, **kwargs):
2167
2163
2168
2164
def _get_cythonized_result (
2169
2165
self ,
2170
- how ,
2171
- grouper ,
2172
- aggregate = False ,
2173
- cython_dtype = None ,
2174
- needs_values = False ,
2175
- needs_mask = False ,
2176
- needs_ngroups = False ,
2177
- result_is_index = False ,
2166
+ how : str ,
2167
+ cython_dtype : np .dtype ,
2168
+ aggregate : bool = False ,
2169
+ needs_values : bool = False ,
2170
+ needs_mask : bool = False ,
2171
+ needs_ngroups : bool = False ,
2172
+ result_is_index : bool = False ,
2178
2173
pre_processing = None ,
2179
2174
post_processing = None ,
2180
2175
** kwargs
@@ -2185,13 +2180,11 @@ def _get_cythonized_result(
2185
2180
Parameters
2186
2181
----------
2187
2182
how : str, Cythonized function name to be called
2188
- grouper : Grouper object containing pertinent group info
2183
+ cython_dtype : np.dtype
2184
+ Type of the array that will be modified by the Cython call.
2189
2185
aggregate : bool, default False
2190
2186
Whether the result should be aggregated to match the number of
2191
2187
groups
2192
- cython_dtype : default None
2193
- Type of the array that will be modified by the Cython call. If
2194
- `None`, the type will be inferred from the values of each slice
2195
2188
needs_values : bool, default False
2196
2189
Whether the values should be a part of the Cython call
2197
2190
signature
@@ -2234,8 +2227,10 @@ def _get_cythonized_result(
2234
2227
"Cannot use 'pre_processing' without specifying 'needs_values'!"
2235
2228
)
2236
2229
2230
+ grouper = self .grouper
2231
+
2237
2232
labels , _ , ngroups = grouper .group_info
2238
- output = collections .OrderedDict ()
2233
+ output = collections .OrderedDict () # type: dict
2239
2234
base_func = getattr (libgroupby , how )
2240
2235
2241
2236
for name , obj in self ._iterate_slices ():
@@ -2246,9 +2241,6 @@ def _get_cythonized_result(
2246
2241
else :
2247
2242
result_sz = len (values )
2248
2243
2249
- if not cython_dtype :
2250
- cython_dtype = values .dtype
2251
-
2252
2244
result = np .zeros (result_sz , dtype = cython_dtype )
2253
2245
func = partial (base_func , result , labels )
2254
2246
inferences = None
@@ -2308,8 +2300,7 @@ def shift(self, periods=1, freq=None, axis=0, fill_value=None):
2308
2300
2309
2301
return self ._get_cythonized_result (
2310
2302
"group_shift_indexer" ,
2311
- self .grouper ,
2312
- cython_dtype = np .int64 ,
2303
+ cython_dtype = np .dtype (np .int64 ),
2313
2304
needs_ngroups = True ,
2314
2305
result_is_index = True ,
2315
2306
periods = periods ,
@@ -2478,11 +2469,13 @@ def _reindex_output(self, output):
2478
2469
2479
2470
2480
2471
@Appender (GroupBy .__doc__ )
2481
- def groupby (obj , by , ** kwds ):
2472
+ def groupby (obj : NDFrame , by , ** kwds ):
2482
2473
if isinstance (obj , Series ):
2483
2474
from pandas .core .groupby .generic import SeriesGroupBy
2484
2475
2485
- klass = SeriesGroupBy
2476
+ klass = (
2477
+ SeriesGroupBy
2478
+ ) # type: Union[Type["SeriesGroupBy"], Type["DataFrameGroupBy"]]
2486
2479
elif isinstance (obj , DataFrame ):
2487
2480
from pandas .core .groupby .generic import DataFrameGroupBy
2488
2481
0 commit comments