@@ -1476,6 +1476,40 @@ def putmask(self, mask, new) -> list[Block]:
1476
1476
1477
1477
return [self ]
1478
1478
1479
+ def fillna (
1480
+ self , value , limit = None , inplace : bool = False , downcast = None
1481
+ ) -> list [Block ]:
1482
+
1483
+ try :
1484
+ new_values = self .values .fillna (value = value , limit = limit )
1485
+ except (TypeError , ValueError ) as err :
1486
+ _catch_deprecated_value_error (err )
1487
+
1488
+ if is_interval_dtype (self .dtype ):
1489
+ # Discussion about what we want to support in the general
1490
+ # case GH#39584
1491
+ blk = self .coerce_to_target_dtype (value )
1492
+ if blk .dtype == _dtype_obj :
1493
+ # For now at least, only support casting e.g.
1494
+ # Interval[int64]->Interval[float64],
1495
+ raise
1496
+ # Never actually reached, but *could* be possible pending GH#45412
1497
+ return blk .fillna (value , limit , inplace , downcast )
1498
+
1499
+ elif isinstance (self , NDArrayBackedExtensionBlock ):
1500
+ # We support filling a DatetimeTZ with a `value` whose timezone
1501
+ # is different by coercing to object.
1502
+ if self .dtype .kind == "m" :
1503
+ # TODO: don't special-case td64
1504
+ raise
1505
+ blk = self .coerce_to_target_dtype (value )
1506
+ return blk .fillna (value , limit , inplace , downcast )
1507
+
1508
+ else :
1509
+ raise
1510
+
1511
+ return [self .make_block_same_class (values = new_values )]
1512
+
1479
1513
def delete (self , loc ) -> None :
1480
1514
"""
1481
1515
Delete given loc(-s) from block in-place.
@@ -1729,12 +1763,6 @@ def getitem_block_index(self, slicer: slice) -> ExtensionBlock:
1729
1763
new_values = self .values [slicer ]
1730
1764
return type (self )(new_values , self ._mgr_locs , ndim = self .ndim )
1731
1765
1732
- def fillna (
1733
- self , value , limit = None , inplace : bool = False , downcast = None
1734
- ) -> list [Block ]:
1735
- values = self .values .fillna (value = value , limit = limit )
1736
- return [self .make_block_same_class (values = values )]
1737
-
1738
1766
def diff (self , n : int , axis : int = 1 ) -> list [Block ]:
1739
1767
if axis == 0 and n != 0 :
1740
1768
# n==0 case will be a no-op so let is fall through
@@ -1858,21 +1886,6 @@ def shift(self, periods: int, axis: int = 0, fill_value: Any = None) -> list[Blo
1858
1886
new_values = values .shift (periods , fill_value = fill_value , axis = axis )
1859
1887
return [self .make_block_same_class (new_values )]
1860
1888
1861
- def fillna (
1862
- self , value , limit = None , inplace : bool = False , downcast = None
1863
- ) -> list [Block ]:
1864
-
1865
- if not self ._can_hold_element (value ) and self .dtype .kind != "m" :
1866
- # We support filling a DatetimeTZ with a `value` whose timezone
1867
- # is different by coercing to object.
1868
- # TODO: don't special-case td64
1869
- return self .coerce_to_target_dtype (value ).fillna (
1870
- value , limit , inplace , downcast
1871
- )
1872
-
1873
- new_values = self .values .fillna (value = value , limit = limit )
1874
- return [self .make_block_same_class (values = new_values )]
1875
-
1876
1889
1877
1890
def _catch_deprecated_value_error (err : Exception ) -> None :
1878
1891
"""
0 commit comments