@@ -1346,32 +1346,44 @@ def fillna(
1346
1346
def pad_or_backfill (
1347
1347
self ,
1348
1348
* ,
1349
- method : FillnaOptions = "pad" ,
1349
+ method : FillnaOptions ,
1350
1350
axis : AxisInt = 0 ,
1351
1351
inplace : bool = False ,
1352
1352
limit : int | None = None ,
1353
1353
limit_area : Literal ["inside" , "outside" ] | None = None ,
1354
1354
downcast : Literal ["infer" ] | None = None ,
1355
1355
using_cow : bool = False ,
1356
- ** kwargs ,
1357
1356
) -> list [Block ]:
1358
- return self .interpolate (
1357
+ if not self ._can_hold_na :
1358
+ # If there are no NAs, then interpolate is a no-op
1359
+ if using_cow :
1360
+ return [self .copy (deep = False )]
1361
+ return [self ] if inplace else [self .copy ()]
1362
+
1363
+ copy , refs = self ._get_refs_and_copy (using_cow , inplace )
1364
+
1365
+ # Dispatch to the PandasArray method.
1366
+ # We know self.array_values is a PandasArray bc EABlock overrides
1367
+ new_values = cast (PandasArray , self .array_values ).pad_or_backfill (
1359
1368
method = method ,
1360
1369
axis = axis ,
1361
- inplace = inplace ,
1362
1370
limit = limit ,
1363
1371
limit_area = limit_area ,
1364
- downcast = downcast ,
1365
- using_cow = using_cow ,
1366
- ** kwargs ,
1372
+ copy = copy ,
1367
1373
)
1368
1374
1375
+ data = extract_array (new_values , extract_numpy = True )
1376
+
1377
+ nb = self .make_block_same_class (data , refs = refs )
1378
+ return nb ._maybe_downcast ([nb ], downcast , using_cow )
1379
+
1380
+ @final
1369
1381
def interpolate (
1370
1382
self ,
1371
1383
* ,
1372
- method : FillnaOptions | InterpolateOptions = "pad" ,
1373
- axis : AxisInt = 0 ,
1374
- index : Index | None = None ,
1384
+ method : InterpolateOptions ,
1385
+ axis : AxisInt ,
1386
+ index : Index ,
1375
1387
inplace : bool = False ,
1376
1388
limit : int | None = None ,
1377
1389
limit_direction : Literal ["forward" , "backward" , "both" ] = "forward" ,
@@ -1381,6 +1393,10 @@ def interpolate(
1381
1393
** kwargs ,
1382
1394
) -> list [Block ]:
1383
1395
inplace = validate_bool_kwarg (inplace , "inplace" )
1396
+ # error: Non-overlapping equality check [...]
1397
+ if method == "asfreq" : # type: ignore[comparison-overlap]
1398
+ # clean_fill_method used to allow this
1399
+ missing .clean_fill_method (method )
1384
1400
1385
1401
if not self ._can_hold_na :
1386
1402
# If there are no NAs, then interpolate is a no-op
@@ -1389,7 +1405,7 @@ def interpolate(
1389
1405
return [self ] if inplace else [self .copy ()]
1390
1406
1391
1407
# TODO(3.0): this case will not be reachable once GH#53638 is enforced
1392
- if not _interp_method_is_pad_or_backfill ( method ) and self .dtype == _dtype_obj :
1408
+ if self .dtype == _dtype_obj :
1393
1409
# only deal with floats
1394
1410
# bc we already checked that can_hold_na, we don't have int dtype here
1395
1411
# test_interp_basic checks that we make a copy here
@@ -1414,29 +1430,17 @@ def interpolate(
1414
1430
1415
1431
copy , refs = self ._get_refs_and_copy (using_cow , inplace )
1416
1432
1417
- # Dispatch to the PandasArray method.
1418
- # We know self.array_values is a PandasArray bc EABlock overrides
1419
- if _interp_method_is_pad_or_backfill (method ):
1420
- # TODO: warn about ignored kwargs, limit_direction, index...?
1421
- new_values = cast (PandasArray , self .array_values ).pad_or_backfill (
1422
- method = cast (FillnaOptions , method ),
1423
- axis = axis ,
1424
- limit = limit ,
1425
- limit_area = limit_area ,
1426
- copy = copy ,
1427
- )
1428
- else :
1429
- assert index is not None # for mypy
1430
- new_values = cast (PandasArray , self .array_values ).interpolate (
1431
- method = cast (InterpolateOptions , method ),
1432
- axis = axis ,
1433
- index = index ,
1434
- limit = limit ,
1435
- limit_direction = limit_direction ,
1436
- limit_area = limit_area ,
1437
- copy = copy ,
1438
- ** kwargs ,
1439
- )
1433
+ # Dispatch to the EA method.
1434
+ new_values = self .array_values .interpolate (
1435
+ method = method ,
1436
+ axis = axis ,
1437
+ index = index ,
1438
+ limit = limit ,
1439
+ limit_direction = limit_direction ,
1440
+ limit_area = limit_area ,
1441
+ copy = copy ,
1442
+ ** kwargs ,
1443
+ )
1440
1444
data = extract_array (new_values , extract_numpy = True )
1441
1445
1442
1446
nb = self .make_block_same_class (data , refs = refs )
@@ -1863,42 +1867,25 @@ def get_values(self, dtype: DtypeObj | None = None) -> np.ndarray:
1863
1867
def values_for_json (self ) -> np .ndarray :
1864
1868
return np .asarray (self .values )
1865
1869
1866
- def interpolate (
1870
+ @final
1871
+ def pad_or_backfill (
1867
1872
self ,
1868
1873
* ,
1869
- method : FillnaOptions | InterpolateOptions = "pad" ,
1870
- index : Index | None = None ,
1871
- axis : int = 0 ,
1874
+ method : FillnaOptions ,
1875
+ axis : AxisInt = 0 ,
1872
1876
inplace : bool = False ,
1873
1877
limit : int | None = None ,
1874
- fill_value = None ,
1878
+ limit_area : Literal ["inside" , "outside" ] | None = None ,
1879
+ downcast : Literal ["infer" ] | None = None ,
1875
1880
using_cow : bool = False ,
1876
- ** kwargs ,
1877
- ):
1881
+ ) -> list [Block ]:
1878
1882
values = self .values
1879
-
1880
- if not _interp_method_is_pad_or_backfill (method ):
1881
- imeth = cast (InterpolateOptions , method )
1882
- return super ().interpolate (
1883
- method = imeth ,
1884
- index = index ,
1885
- axis = axis ,
1886
- inplace = inplace ,
1887
- limit = limit ,
1888
- fill_value = fill_value ,
1889
- using_cow = using_cow ,
1890
- ** kwargs ,
1891
- )
1883
+ if values .ndim == 2 and axis == 0 :
1884
+ # NDArrayBackedExtensionArray.fillna assumes axis=1
1885
+ new_values = values .T .fillna (method = method , limit = limit ).T
1892
1886
else :
1893
- meth = cast (FillnaOptions , method )
1894
- if values .ndim == 2 and axis == 0 :
1895
- # NDArrayBackedExtensionArray.fillna assumes axis=1
1896
- new_values = values .T .fillna (
1897
- value = fill_value , method = meth , limit = limit
1898
- ).T
1899
- else :
1900
- new_values = values .fillna (value = fill_value , method = meth , limit = limit )
1901
- return self .make_block_same_class (new_values )
1887
+ new_values = values .fillna (method = method , limit = limit )
1888
+ return [self .make_block_same_class (new_values )]
1902
1889
1903
1890
1904
1891
class ExtensionBlock (libinternals .Block , EABackedBlock ):
@@ -2553,14 +2540,3 @@ def external_values(values: ArrayLike) -> ArrayLike:
2553
2540
# TODO(CoW) we should also mark our ExtensionArrays as read-only
2554
2541
2555
2542
return values
2556
-
2557
-
2558
- def _interp_method_is_pad_or_backfill (method : str ) -> bool :
2559
- try :
2560
- m = missing .clean_fill_method (method )
2561
- except ValueError :
2562
- m = None
2563
- if method == "asfreq" :
2564
- # clean_fill_method used to allow this
2565
- raise
2566
- return m is not None
0 commit comments