Skip to content

Commit 7d79cc6

Browse files
authored
PERF: ExtensionBlock.fillna dispatch to underlying arrays (#50078)
* ExtensionBlock.fillna to dispatch * whatsnew * special case interval dtype
1 parent 0119bdc commit 7d79cc6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

asv_bench/benchmarks/series_methods.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Fillna:
8585
[
8686
"datetime64[ns]",
8787
"float64",
88+
"Float64",
8889
"Int64",
8990
"int64[pyarrow]",
9091
"string",
@@ -99,7 +100,7 @@ def setup(self, dtype, method):
99100
if dtype == "datetime64[ns]":
100101
data = date_range("2000-01-01", freq="S", periods=N)
101102
na_value = NaT
102-
elif dtype == "float64":
103+
elif dtype in ("float64", "Float64"):
103104
data = np.random.randn(N)
104105
na_value = np.nan
105106
elif dtype in ("Int64", "int64[pyarrow]"):

doc/source/whatsnew/v2.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ Performance improvements
653653
- Performance improvement in :meth:`MultiIndex.isin` when ``level=None`` (:issue:`48622`, :issue:`49577`)
654654
- Performance improvement in :meth:`MultiIndex.putmask` (:issue:`49830`)
655655
- Performance improvement in :meth:`Index.union` and :meth:`MultiIndex.union` when index contains duplicates (:issue:`48900`)
656-
- Performance improvement in :meth:`Series.fillna` for pyarrow-backed dtypes (:issue:`49722`)
656+
- Performance improvement in :meth:`Series.fillna` for extension array dtypes (:issue:`49722`, :issue:`50078`)
657657
- Performance improvement for :meth:`Series.value_counts` with nullable dtype (:issue:`48338`)
658658
- Performance improvement for :class:`Series` constructor passing integer numpy array with nullable dtype (:issue:`48338`)
659659
- Performance improvement for :class:`DatetimeIndex` constructor passing a list (:issue:`48609`)

pandas/core/internals/blocks.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,6 @@ def where(self, other, cond, _downcast: str | bool = "infer") -> list[Block]:
11271127

11281128
return [self.make_block(result)]
11291129

1130-
@final
11311130
def fillna(
11321131
self, value, limit: int | None = None, inplace: bool = False, downcast=None
11331132
) -> list[Block]:
@@ -1592,6 +1591,18 @@ class ExtensionBlock(libinternals.Block, EABackedBlock):
15921591

15931592
values: ExtensionArray
15941593

1594+
def fillna(
1595+
self, value, limit: int | None = None, inplace: bool = False, downcast=None
1596+
) -> list[Block]:
1597+
if is_interval_dtype(self.dtype):
1598+
# Block.fillna handles coercion (test_fillna_interval)
1599+
return super().fillna(
1600+
value=value, limit=limit, inplace=inplace, downcast=downcast
1601+
)
1602+
new_values = self.values.fillna(value=value, method=None, limit=limit)
1603+
nb = self.make_block_same_class(new_values)
1604+
return nb._maybe_downcast([nb], downcast)
1605+
15951606
@cache_readonly
15961607
def shape(self) -> Shape:
15971608
# TODO(EA2D): override unnecessary with 2D EAs

0 commit comments

Comments
 (0)