@@ -1397,6 +1397,17 @@ def test_interp_limit_area(self):
1397
1397
with pytest .raises (ValueError , match = msg ):
1398
1398
s .interpolate (method = "linear" , limit_area = "abc" )
1399
1399
1400
+ def test_interp_limit_area_with_pad (self ):
1401
+ # Test for issue #26796 -- using `limit_area` with `method=pad`
1402
+ s = Series ([np .nan , np .nan , 3 , np .nan , np .nan , np .nan , 7 , np .nan , np .nan ])
1403
+ expected = Series ([np .nan , np .nan , 3 , 3 , 3 , 3 , 7 , np .nan , np .nan ])
1404
+ result = s .interpolate (method = "pad" , limit_area = "inside" )
1405
+ tm .assert_series_equal (result , expected )
1406
+
1407
+ expected = Series ([np .nan , np .nan , 3 , np .nan , np .nan , np .nan , 7 , 7 , 7 ])
1408
+ result = s .interpolate (method = "pad" , limit_area = "outside" )
1409
+ tm .assert_series_equal (result , expected )
1410
+
1400
1411
def test_interp_limit_direction (self ):
1401
1412
# These tests are for issue #9218 -- fill NaNs in both directions.
1402
1413
s = Series ([1 , 3 , np .nan , np .nan , np .nan , 11 ])
@@ -1422,6 +1433,38 @@ def test_interp_limit_direction(self):
1422
1433
result = s .interpolate (method = "linear" , limit = 1 , limit_direction = "both" )
1423
1434
tm .assert_series_equal (result , expected )
1424
1435
1436
+ def test_interp_limit_direction_with_pad_error (self ):
1437
+ # Since `pad` forces a forward fill and `bfill` forces a backward fill
1438
+ # they should not be used together with `limit_direction`
1439
+ s = Series ([1 , 3 , np .nan , np .nan , np .nan , 11 ])
1440
+
1441
+ with pytest .raises (
1442
+ ValueError , match = "`limit_direction` must not be `backward` for method `pad`"
1443
+ ):
1444
+ s .interpolate (method = "pad" , limit = 1 , limit_direction = "backward" )
1445
+
1446
+ with pytest .raises (
1447
+ ValueError , match = "`limit_direction` must not be `backward` for method `ffill`"
1448
+ ):
1449
+ s .interpolate (method = "ffill" , limit = 1 , limit_direction = "backward" )
1450
+
1451
+ with pytest .raises (
1452
+ ValueError , match = "`limit_direction` must not be `both` for method `ffill`"
1453
+ ):
1454
+ s .interpolate (method = "ffill" , limit = 1 , limit_direction = "both" )
1455
+
1456
+ with pytest .raises (
1457
+ ValueError ,
1458
+ match = "`limit_direction` must not be `forward` for method `backfill`"
1459
+ ):
1460
+ s .interpolate (method = "backfill" , limit = 1 , limit_direction = "forward" )
1461
+
1462
+ with pytest .raises (
1463
+ ValueError ,
1464
+ match = "`limit_direction` must not be `forward` for method `bfill`"
1465
+ ):
1466
+ s .interpolate (method = "bfill" , limit = 1 , limit_direction = "forward" )
1467
+
1425
1468
def test_interp_limit_to_ends (self ):
1426
1469
# These test are for issue #10420 -- flow back to beginning.
1427
1470
s = Series ([np .nan , np .nan , 5 , 7 , 9 , np .nan ])
0 commit comments