Skip to content

Commit 2921441

Browse files
PERF: use isna_array instead of isna in ArrayManager.fillna
1 parent 18de3ac commit 2921441

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

pandas/core/dtypes/missing.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import pandas._libs.missing as libmissing
1313
from pandas._libs.tslibs import (
1414
NaT,
15+
Period,
1516
iNaT,
1617
)
1718
from pandas._typing import (
@@ -210,6 +211,7 @@ def _use_inf_as_na(key):
210211
"""
211212
inf_as_na = get_option(key)
212213
globals()["_isna"] = partial(_isna, inf_as_na=inf_as_na)
214+
globals()["_isna_array"] = partial(_isna_array, inf_as_na=inf_as_na)
213215
if inf_as_na:
214216
globals()["nan_checker"] = lambda x: ~np.isfinite(x)
215217
globals()["INF_AS_NA"] = True
@@ -244,7 +246,8 @@ def _isna_array(values: ArrayLike, inf_as_na: bool = False):
244246
result = values.isna()
245247
elif is_string_or_object_np_dtype(values.dtype):
246248
result = _isna_string_dtype(values, inf_as_na=inf_as_na)
247-
elif needs_i8_conversion(dtype):
249+
# elif needs_i8_conversion(dtype):
250+
elif dtype.kind in "mM" or (dtype.kind == "O" and dtype.type is Period):
248251
# this is the NaT pattern
249252
result = values.view("i8") == iNaT
250253
else:

pandas/core/internals/array_manager.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
)
4949
from pandas.core.dtypes.inference import is_inferred_bool_dtype
5050
from pandas.core.dtypes.missing import (
51+
_isna_array,
5152
array_equals,
5253
isna,
5354
na_value_for_dtype,
@@ -192,6 +193,7 @@ def apply(
192193
f,
193194
align_keys: list[str] | None = None,
194195
ignore_failures: bool = False,
196+
verify_integrity=True,
195197
**kwargs,
196198
) -> T:
197199
"""
@@ -262,7 +264,7 @@ def apply(
262264

263265
# error: Argument 1 to "ArrayManager" has incompatible type "List[ndarray]";
264266
# expected "List[Union[ndarray, ExtensionArray]]"
265-
return type(self)(result_arrays, new_axes) # type: ignore[arg-type]
267+
return type(self)(result_arrays, new_axes, verify_integrity=verify_integrity) # type: ignore[arg-type]
266268

267269
def apply_with_block(self: T, f, align_keys=None, swap_axis=True, **kwargs) -> T:
268270
# switch axis to follow BlockManager logic
@@ -440,6 +442,9 @@ def replace_list(
440442
def to_native_types(self, **kwargs):
441443
return self.apply(to_native_types, **kwargs)
442444

445+
def isna(self: T, func=None) -> T:
446+
return self.apply(_isna_array, verify_integrity=False)
447+
443448
@property
444449
def is_mixed_type(self) -> bool:
445450
return True

pandas/core/internals/base.py

-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ def apply(
135135
) -> T:
136136
raise AbstractMethodError(self)
137137

138-
@final
139138
def isna(self: T, func) -> T:
140139
return self.apply("apply", func=func)
141140

0 commit comments

Comments
 (0)