1
+ from __future__ import annotations
2
+
1
3
import abc
2
4
import inspect
3
5
from typing import TYPE_CHECKING , Any , Dict , Iterator , List , Optional , Tuple , Type , cast
33
35
34
36
35
37
def frame_apply (
36
- obj : " DataFrame" ,
38
+ obj : DataFrame ,
37
39
how : str ,
38
40
func : AggFuncType ,
39
41
axis : Axis = 0 ,
@@ -69,30 +71,30 @@ class FrameApply(metaclass=abc.ABCMeta):
69
71
70
72
@property
71
73
@abc .abstractmethod
72
- def result_index (self ) -> " Index" :
74
+ def result_index (self ) -> Index :
73
75
pass
74
76
75
77
@property
76
78
@abc .abstractmethod
77
- def result_columns (self ) -> " Index" :
79
+ def result_columns (self ) -> Index :
78
80
pass
79
81
80
82
@property
81
83
@abc .abstractmethod
82
- def series_generator (self ) -> Iterator [" Series" ]:
84
+ def series_generator (self ) -> Iterator [Series ]:
83
85
pass
84
86
85
87
@abc .abstractmethod
86
88
def wrap_results_for_axis (
87
- self , results : ResType , res_index : " Index"
89
+ self , results : ResType , res_index : Index
88
90
) -> FrameOrSeriesUnion :
89
91
pass
90
92
91
93
# ---------------------------------------------------------------
92
94
93
95
def __init__ (
94
96
self ,
95
- obj : " DataFrame" ,
97
+ obj : DataFrame ,
96
98
how : str ,
97
99
func ,
98
100
raw : bool ,
@@ -131,27 +133,27 @@ def f(x):
131
133
self .f : AggFuncType = f
132
134
133
135
@property
134
- def res_columns (self ) -> " Index" :
136
+ def res_columns (self ) -> Index :
135
137
return self .result_columns
136
138
137
139
@property
138
- def columns (self ) -> " Index" :
140
+ def columns (self ) -> Index :
139
141
return self .obj .columns
140
142
141
143
@property
142
- def index (self ) -> " Index" :
144
+ def index (self ) -> Index :
143
145
return self .obj .index
144
146
145
147
@cache_readonly
146
148
def values (self ):
147
149
return self .obj .values
148
150
149
151
@cache_readonly
150
- def dtypes (self ) -> " Series" :
152
+ def dtypes (self ) -> Series :
151
153
return self .obj .dtypes
152
154
153
155
@property
154
- def agg_axis (self ) -> " Index" :
156
+ def agg_axis (self ) -> Index :
155
157
return self .obj ._get_agg_axis (self .axis )
156
158
157
159
def get_result (self ):
@@ -311,7 +313,7 @@ def wrapper(*args, **kwargs):
311
313
else :
312
314
return self .obj ._constructor_sliced (result , index = self .agg_axis )
313
315
314
- def apply_broadcast (self , target : " DataFrame" ) -> " DataFrame" :
316
+ def apply_broadcast (self , target : DataFrame ) -> DataFrame :
315
317
assert callable (self .f )
316
318
317
319
result_values = np .empty_like (target .values )
@@ -346,7 +348,7 @@ def apply_standard(self):
346
348
# wrap results
347
349
return self .wrap_results (results , res_index )
348
350
349
- def apply_series_generator (self ) -> Tuple [ResType , " Index" ]:
351
+ def apply_series_generator (self ) -> Tuple [ResType , Index ]:
350
352
assert callable (self .f )
351
353
352
354
series_gen = self .series_generator
@@ -365,7 +367,7 @@ def apply_series_generator(self) -> Tuple[ResType, "Index"]:
365
367
366
368
return results , res_index
367
369
368
- def wrap_results (self , results : ResType , res_index : " Index" ) -> FrameOrSeriesUnion :
370
+ def wrap_results (self , results : ResType , res_index : Index ) -> FrameOrSeriesUnion :
369
371
from pandas import Series
370
372
371
373
# see if we can infer the results
@@ -392,23 +394,23 @@ def wrap_results(self, results: ResType, res_index: "Index") -> FrameOrSeriesUni
392
394
class FrameRowApply (FrameApply ):
393
395
axis = 0
394
396
395
- def apply_broadcast (self , target : " DataFrame" ) -> " DataFrame" :
397
+ def apply_broadcast (self , target : DataFrame ) -> DataFrame :
396
398
return super ().apply_broadcast (target )
397
399
398
400
@property
399
401
def series_generator (self ):
400
402
return (self .obj ._ixs (i , axis = 1 ) for i in range (len (self .columns )))
401
403
402
404
@property
403
- def result_index (self ) -> " Index" :
405
+ def result_index (self ) -> Index :
404
406
return self .columns
405
407
406
408
@property
407
- def result_columns (self ) -> " Index" :
409
+ def result_columns (self ) -> Index :
408
410
return self .index
409
411
410
412
def wrap_results_for_axis (
411
- self , results : ResType , res_index : " Index"
413
+ self , results : ResType , res_index : Index
412
414
) -> FrameOrSeriesUnion :
413
415
""" return the results for the rows """
414
416
@@ -452,7 +454,7 @@ def wrap_results_for_axis(
452
454
class FrameColumnApply (FrameApply ):
453
455
axis = 1
454
456
455
- def apply_broadcast (self , target : " DataFrame" ) -> " DataFrame" :
457
+ def apply_broadcast (self , target : DataFrame ) -> DataFrame :
456
458
result = super ().apply_broadcast (target .T )
457
459
return result .T
458
460
@@ -483,15 +485,15 @@ def series_generator(self):
483
485
yield ser
484
486
485
487
@property
486
- def result_index (self ) -> " Index" :
488
+ def result_index (self ) -> Index :
487
489
return self .index
488
490
489
491
@property
490
- def result_columns (self ) -> " Index" :
492
+ def result_columns (self ) -> Index :
491
493
return self .columns
492
494
493
495
def wrap_results_for_axis (
494
- self , results : ResType , res_index : " Index"
496
+ self , results : ResType , res_index : Index
495
497
) -> FrameOrSeriesUnion :
496
498
""" return the results for the columns """
497
499
result : FrameOrSeriesUnion
@@ -511,7 +513,7 @@ def wrap_results_for_axis(
511
513
512
514
return result
513
515
514
- def infer_to_same_shape (self , results : ResType , res_index : " Index" ) -> " DataFrame" :
516
+ def infer_to_same_shape (self , results : ResType , res_index : Index ) -> DataFrame :
515
517
""" infer the results to the same shape as the input object """
516
518
result = self .obj ._constructor (data = results )
517
519
result = result .T
0 commit comments