Skip to content

Commit aa91eb4

Browse files
authored
CLN: de-duplicate _isnan (#37373)
1 parent d240cb8 commit aa91eb4

File tree

4 files changed

+5
-19
lines changed

4 files changed

+5
-19
lines changed

pandas/core/indexes/category.py

-5
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@ def astype(self, dtype, copy=True):
377377

378378
return Index.astype(self, dtype=dtype, copy=copy)
379379

380-
@cache_readonly
381-
def _isnan(self):
382-
""" return if each value is nan"""
383-
return self._data.codes == -1
384-
385380
@doc(Index.fillna)
386381
def fillna(self, value, downcast=None):
387382
value = self._validate_scalar(value)

pandas/core/indexes/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def wrapper(left, right):
7878

7979

8080
@inherit_names(
81-
["inferred_freq", "_isnan", "_resolution_obj", "resolution"],
81+
["inferred_freq", "_resolution_obj", "resolution"],
8282
DatetimeLikeArrayMixin,
8383
cache=True,
8484
)

pandas/core/indexes/extension.py

+4
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,7 @@ def astype(self, dtype, copy=True):
277277
# pass copy=False because any copying will be done in the
278278
# _data.astype call above
279279
return Index(new_values, dtype=new_values.dtype, name=self.name, copy=False)
280+
281+
@cache_readonly
282+
def _isnan(self) -> np.ndarray:
283+
return self._data.isna()

pandas/core/indexes/interval.py

-13
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
is_object_dtype,
3838
is_scalar,
3939
)
40-
from pandas.core.dtypes.missing import isna
4140

4241
from pandas.core.algorithms import take_1d
4342
from pandas.core.arrays.interval import IntervalArray, _interval_shared_docs
@@ -192,9 +191,6 @@ class IntervalIndex(IntervalMixin, ExtensionIndex):
192191
# we would like our indexing holder to defer to us
193192
_defer_to_indexing = True
194193

195-
# Immutable, so we are able to cache computations like isna in '_mask'
196-
_mask = None
197-
198194
_data: IntervalArray
199195
_values: IntervalArray
200196

@@ -342,15 +338,6 @@ def _shallow_copy(
342338
result._cache = self._cache
343339
return result
344340

345-
@cache_readonly
346-
def _isnan(self):
347-
"""
348-
Return a mask indicating if each value is NA.
349-
"""
350-
if self._mask is None:
351-
self._mask = isna(self.left)
352-
return self._mask
353-
354341
@cache_readonly
355342
def _engine(self):
356343
left = self._maybe_convert_i8(self.left)

0 commit comments

Comments
 (0)