30
30
31
31
from pandas ._config import config
32
32
33
- from pandas ._libs import Timestamp , iNaT , lib
33
+ from pandas ._libs import Timestamp , lib
34
34
from pandas ._typing import (
35
35
Axis ,
36
36
FilePathOrBuffer ,
@@ -10106,8 +10106,6 @@ def mad(self, axis=None, skipna=None, level=None):
10106
10106
desc = "minimum" ,
10107
10107
accum_func = np .minimum .accumulate ,
10108
10108
accum_func_name = "min" ,
10109
- mask_a = np .inf ,
10110
- mask_b = np .nan ,
10111
10109
examples = _cummin_examples ,
10112
10110
)
10113
10111
cls .cumsum = _make_cum_function (
@@ -10119,8 +10117,6 @@ def mad(self, axis=None, skipna=None, level=None):
10119
10117
desc = "sum" ,
10120
10118
accum_func = np .cumsum ,
10121
10119
accum_func_name = "sum" ,
10122
- mask_a = 0.0 ,
10123
- mask_b = np .nan ,
10124
10120
examples = _cumsum_examples ,
10125
10121
)
10126
10122
cls .cumprod = _make_cum_function (
@@ -10132,8 +10128,6 @@ def mad(self, axis=None, skipna=None, level=None):
10132
10128
desc = "product" ,
10133
10129
accum_func = np .cumprod ,
10134
10130
accum_func_name = "prod" ,
10135
- mask_a = 1.0 ,
10136
- mask_b = np .nan ,
10137
10131
examples = _cumprod_examples ,
10138
10132
)
10139
10133
cls .cummax = _make_cum_function (
@@ -10145,8 +10139,6 @@ def mad(self, axis=None, skipna=None, level=None):
10145
10139
desc = "maximum" ,
10146
10140
accum_func = np .maximum .accumulate ,
10147
10141
accum_func_name = "max" ,
10148
- mask_a = - np .inf ,
10149
- mask_b = np .nan ,
10150
10142
examples = _cummax_examples ,
10151
10143
)
10152
10144
@@ -11186,8 +11178,6 @@ def _make_cum_function(
11186
11178
desc : str ,
11187
11179
accum_func : Callable ,
11188
11180
accum_func_name : str ,
11189
- mask_a : float ,
11190
- mask_b : float ,
11191
11181
examples : str ,
11192
11182
) -> Callable :
11193
11183
@Substitution (
@@ -11209,61 +11199,15 @@ def cum_func(self, axis=None, skipna=True, *args, **kwargs):
11209
11199
if axis == 1 :
11210
11200
return cum_func (self .T , axis = 0 , skipna = skipna , * args , ** kwargs ).T
11211
11201
11212
- def na_accum_func (blk_values ):
11213
- # We will be applying this function to block values
11214
- if blk_values .dtype .kind in ["m" , "M" ]:
11215
- # GH#30460, GH#29058
11216
- # numpy 1.18 started sorting NaTs at the end instead of beginning,
11217
- # so we need to work around to maintain backwards-consistency.
11218
- orig_dtype = blk_values .dtype
11219
-
11220
- # We need to define mask before masking NaTs
11221
- mask = isna (blk_values )
11222
-
11223
- if accum_func == np .minimum .accumulate :
11224
- # Note: the accum_func comparison fails as an "is" comparison
11225
- y = blk_values .view ("i8" )
11226
- y [mask ] = np .iinfo (np .int64 ).max
11227
- changed = True
11228
- else :
11229
- y = blk_values
11230
- changed = False
11231
-
11232
- result = accum_func (y .view ("i8" ), axis )
11233
- if skipna :
11234
- np .putmask (result , mask , iNaT )
11235
- elif accum_func == np .minimum .accumulate :
11236
- # Restore NaTs that we masked previously
11237
- nz = (~ np .asarray (mask )).nonzero ()[0 ]
11238
- if len (nz ):
11239
- # everything up to the first non-na entry stays NaT
11240
- result [: nz [0 ]] = iNaT
11241
-
11242
- if changed :
11243
- # restore NaT elements
11244
- y [mask ] = iNaT # TODO: could try/finally for this?
11245
-
11246
- if isinstance (blk_values , np .ndarray ):
11247
- result = result .view (orig_dtype )
11248
- else :
11249
- # DatetimeArray
11250
- result = type (blk_values )._from_sequence (result , dtype = orig_dtype )
11251
-
11252
- elif skipna and not issubclass (
11253
- blk_values .dtype .type , (np .integer , np .bool_ )
11254
- ):
11255
- vals = blk_values .copy ().T
11256
- mask = isna (vals )
11257
- np .putmask (vals , mask , mask_a )
11258
- result = accum_func (vals , axis )
11259
- np .putmask (result , mask , mask_b )
11260
- else :
11261
- result = accum_func (blk_values .T , axis )
11202
+ def block_accum_func (blk_values ):
11203
+ values = blk_values .T if hasattr (blk_values , "T" ) else blk_values
11262
11204
11263
- # transpose back for ndarray, not for EA
11264
- return result .T if hasattr (result , "T" ) else result
11205
+ result = nanops .na_accum_func (values , accum_func , skipna = skipna )
11206
+
11207
+ result = result .T if hasattr (result , "T" ) else result
11208
+ return result
11265
11209
11266
- result = self ._data .apply (na_accum_func )
11210
+ result = self ._data .apply (block_accum_func )
11267
11211
11268
11212
d = self ._construct_axes_dict ()
11269
11213
d ["copy" ] = False
0 commit comments