6
6
import itertools
7
7
from typing import (
8
8
TYPE_CHECKING ,
9
- Any ,
10
9
Callable ,
11
10
Hashable ,
12
11
Literal ,
16
15
17
16
from pandas ._libs import (
18
17
NaT ,
19
- algos as libalgos ,
20
18
lib ,
21
19
)
22
- from pandas .util ._validators import validate_bool_kwarg
23
20
24
21
from pandas .core .dtypes .astype import (
25
22
astype_array ,
@@ -261,10 +258,11 @@ def apply(
261
258
# expected "List[Union[ndarray, ExtensionArray]]"
262
259
return type (self )(result_arrays , new_axes ) # type: ignore[arg-type]
263
260
264
- def apply_with_block (
265
- self , f , align_keys = None , swap_axis : bool = True , ** kwargs
266
- ) -> Self :
261
+ def apply_with_block (self , f , align_keys = None , ** kwargs ) -> Self :
267
262
# switch axis to follow BlockManager logic
263
+ swap_axis = True
264
+ if f == "interpolate" :
265
+ swap_axis = False
268
266
if swap_axis and "axis" in kwargs and self .ndim == 2 :
269
267
kwargs ["axis" ] = 1 if kwargs ["axis" ] == 0 else 0
270
268
@@ -319,50 +317,13 @@ def apply_with_block(
319
317
320
318
return type (self )(result_arrays , self ._axes )
321
319
322
- def where (self , other , cond , align : bool ) -> Self :
323
- if align :
324
- align_keys = ["other" , "cond" ]
325
- else :
326
- align_keys = ["cond" ]
327
- other = extract_array (other , extract_numpy = True )
328
-
329
- return self .apply_with_block (
330
- "where" ,
331
- align_keys = align_keys ,
332
- other = other ,
333
- cond = cond ,
334
- )
335
-
336
- def round (self , decimals : int , using_cow : bool = False ) -> Self :
337
- return self .apply_with_block ("round" , decimals = decimals , using_cow = using_cow )
338
-
339
320
def setitem (self , indexer , value ) -> Self :
340
321
return self .apply_with_block ("setitem" , indexer = indexer , value = value )
341
322
342
- def putmask (self , mask , new , align : bool = True ) -> Self :
343
- if align :
344
- align_keys = ["new" , "mask" ]
345
- else :
346
- align_keys = ["mask" ]
347
- new = extract_array (new , extract_numpy = True )
348
-
349
- return self .apply_with_block (
350
- "putmask" ,
351
- align_keys = align_keys ,
352
- mask = mask ,
353
- new = new ,
354
- )
355
-
356
323
def diff (self , n : int ) -> Self :
357
324
assert self .ndim == 2 # caller ensures
358
325
return self .apply (algos .diff , n = n )
359
326
360
- def pad_or_backfill (self , ** kwargs ) -> Self :
361
- return self .apply_with_block ("pad_or_backfill" , swap_axis = False , ** kwargs )
362
-
363
- def interpolate (self , ** kwargs ) -> Self :
364
- return self .apply_with_block ("interpolate" , swap_axis = False , ** kwargs )
365
-
366
327
def shift (self , periods : int , axis : AxisInt , fill_value ) -> Self :
367
328
if fill_value is lib .no_default :
368
329
fill_value = None
@@ -375,15 +336,6 @@ def shift(self, periods: int, axis: AxisInt, fill_value) -> Self:
375
336
"shift" , periods = periods , axis = axis , fill_value = fill_value
376
337
)
377
338
378
- def fillna (self , value , limit : int | None , inplace : bool , downcast ) -> Self :
379
- if limit is not None :
380
- # Do this validation even if we go through one of the no-op paths
381
- limit = libalgos .validate_limit (None , limit = limit )
382
-
383
- return self .apply_with_block (
384
- "fillna" , value = value , limit = limit , inplace = inplace , downcast = downcast
385
- )
386
-
387
339
def astype (self , dtype , copy : bool | None = False , errors : str = "raise" ) -> Self :
388
340
if copy is None :
389
341
copy = True
@@ -410,36 +362,6 @@ def _convert(arr):
410
362
411
363
return self .apply (_convert )
412
364
413
- def replace_regex (self , ** kwargs ) -> Self :
414
- return self .apply_with_block ("_replace_regex" , ** kwargs )
415
-
416
- def replace (self , to_replace , value , inplace : bool ) -> Self :
417
- inplace = validate_bool_kwarg (inplace , "inplace" )
418
- assert np .ndim (value ) == 0 , value
419
- # TODO "replace" is right now implemented on the blocks, we should move
420
- # it to general array algos so it can be reused here
421
- return self .apply_with_block (
422
- "replace" , value = value , to_replace = to_replace , inplace = inplace
423
- )
424
-
425
- def replace_list (
426
- self ,
427
- src_list : list [Any ],
428
- dest_list : list [Any ],
429
- inplace : bool = False ,
430
- regex : bool = False ,
431
- ) -> Self :
432
- """do a list replace"""
433
- inplace = validate_bool_kwarg (inplace , "inplace" )
434
-
435
- return self .apply_with_block (
436
- "replace_list" ,
437
- src_list = src_list ,
438
- dest_list = dest_list ,
439
- inplace = inplace ,
440
- regex = regex ,
441
- )
442
-
443
365
def to_native_types (self , ** kwargs ) -> Self :
444
366
return self .apply (to_native_types , ** kwargs )
445
367
0 commit comments