File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2216,6 +2216,30 @@ def equals(self, other: object) -> bool:
2216
2216
return np .array_equal (self ._codes , other ._codes )
2217
2217
return False
2218
2218
2219
+ def _accumulate (self , name : str , skipna : bool = True , ** kwargs ):
2220
+ if self .ordered :
2221
+ if name == "cummin" :
2222
+ func = np .minimum .accumulate
2223
+ elif name == "cummax" :
2224
+ func = np .maximum .accumulate
2225
+ else :
2226
+ raise NotImplementedError (f"cannot perform { name } with type { self .dtype } " )
2227
+
2228
+ codes = self .codes .copy ()
2229
+ mask = self .codes == - 1
2230
+ codes [mask ] = self .max ()
2231
+ result_codes = func (codes )
2232
+
2233
+ # Restore the original NaN values
2234
+ result_codes [mask ] = - 1
2235
+
2236
+ return pd .Categorical .from_codes (
2237
+ result_codes , categories = self .categories , ordered = self .ordered
2238
+ )
2239
+ else :
2240
+ raise NotImplementedError (f"cannot perform { name } with type { self .dtype } " )
2241
+
2242
+
2219
2243
@classmethod
2220
2244
def _concat_same_type (cls , to_concat : Sequence [Self ], axis : AxisInt = 0 ) -> Self :
2221
2245
from pandas .core .dtypes .concat import union_categoricals
You can’t perform that action at this time.
0 commit comments