64
64
SelectionMixin ,
65
65
)
66
66
import pandas .core .common as common
67
- from pandas .core .construction import extract_array
68
67
from pandas .core .indexes .api import (
69
68
Index ,
70
69
MultiIndex ,
@@ -301,11 +300,8 @@ def __iter__(self):
301
300
result = obj .iloc [slice (s , e )]
302
301
yield result
303
302
304
- def _prep_values (self , values : Optional [ np . ndarray ] = None ) -> np .ndarray :
303
+ def _prep_values (self , values : ArrayLike ) -> np .ndarray :
305
304
"""Convert input to numpy arrays for Cython routines"""
306
- if values is None :
307
- values = extract_array (self ._selected_obj , extract_numpy = True )
308
-
309
305
if needs_i8_conversion (values .dtype ):
310
306
raise NotImplementedError (
311
307
f"ops for { type (self ).__name__ } for this "
@@ -358,6 +354,16 @@ def _index_array(self):
358
354
return self ._on .asi8
359
355
return None
360
356
357
+ def _resolve_output (self , out : DataFrame , obj : DataFrame ) -> DataFrame :
358
+ """Validate and finalize result."""
359
+ if out .shape [1 ] == 0 and obj .shape [1 ] > 0 :
360
+ raise DataError ("No numeric types to aggregate" )
361
+ elif out .shape [1 ] == 0 :
362
+ return obj .astype ("float64" )
363
+
364
+ self ._insert_on_column (out , obj )
365
+ return out
366
+
361
367
def _get_window_indexer (self ) -> BaseIndexer :
362
368
"""
363
369
Return an indexer class that will compute the window start and end bounds
@@ -421,13 +427,7 @@ def hfunc2d(values: ArrayLike) -> ArrayLike:
421
427
new_mgr = mgr .apply (hfunc , ignore_failures = True )
422
428
out = obj ._constructor (new_mgr )
423
429
424
- if out .shape [1 ] == 0 and obj .shape [1 ] > 0 :
425
- raise DataError ("No numeric types to aggregate" )
426
- elif out .shape [1 ] == 0 :
427
- return obj .astype ("float64" )
428
-
429
- self ._insert_on_column (out , obj )
430
- return out
430
+ return self ._resolve_output (out , obj )
431
431
432
432
def _apply_tablewise (
433
433
self , homogeneous_func : Callable [..., ArrayLike ], name : Optional [str ] = None
@@ -444,13 +444,7 @@ def _apply_tablewise(
444
444
result = result .T if self .axis == 1 else result
445
445
out = obj ._constructor (result , index = obj .index , columns = obj .columns )
446
446
447
- if out .shape [1 ] == 0 and obj .shape [1 ] > 0 :
448
- raise DataError ("No numeric types to aggregate" )
449
- elif out .shape [1 ] == 0 :
450
- return obj .astype ("float64" )
451
-
452
- self ._insert_on_column (out , obj )
453
- return out
447
+ return self ._resolve_output (out , obj )
454
448
455
449
def _apply_pairwise (
456
450
self ,
@@ -2203,7 +2197,6 @@ def _get_window_indexer(self) -> GroupbyIndexer:
2203
2197
rolling_indexer : Type [BaseIndexer ]
2204
2198
indexer_kwargs : Optional [Dict [str , Any ]] = None
2205
2199
index_array = self ._index_array
2206
- window = self .window
2207
2200
if isinstance (self .window , BaseIndexer ):
2208
2201
rolling_indexer = type (self .window )
2209
2202
indexer_kwargs = self .window .__dict__
@@ -2216,7 +2209,7 @@ def _get_window_indexer(self) -> GroupbyIndexer:
2216
2209
window = self ._win_freq_i8
2217
2210
else :
2218
2211
rolling_indexer = FixedWindowIndexer
2219
- index_array = None
2212
+ window = self . window
2220
2213
window_indexer = GroupbyIndexer (
2221
2214
index_array = index_array ,
2222
2215
window_size = window ,
0 commit comments