Skip to content

Commit d848ab2

Browse files
committed
fix comments
1 parent c9761e3 commit d848ab2

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

pandas/core/indexes/base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2424,12 +2424,13 @@ def _is_multi(self) -> bool:
24242424
"""
24252425
return isinstance(self, ABCMultiIndex)
24262426

2427+
@final
24272428
@classmethod
24282429
def _is_num_index(cls) -> bool:
24292430
"""
2430-
Whether self is a NumIndex, but not *not* Int64Index, UInt64Index, FloatIndex.
2431+
Check if this is a NumericIndex, but *not* Int64Index, UInt64Index, FloatIndex.
24312432
2432-
Typically used to check if an operation should return NumIndex or plain Index.
2433+
Used to check if an operation should return NumericIndex or plain Index.
24332434
"""
24342435
from pandas.core.indexes.numeric import (
24352436
Float64Index,

pandas/core/indexes/category.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,21 @@ def astype(self, dtype, copy: bool = True) -> Index:
287287

288288
dtype = pandas_dtype(dtype)
289289

290-
cat = self.categories
290+
categories = self.categories
291291
# the super method always returns Int64Index, UInt64Index and Float64Index
292292
# but if e.g. the categories are a NumIndex with dtype float32, we want to
293293
# return an index with the same dtype as self.categories.
294-
if cat._is_num_index():
295-
assert isinstance(cat, NumericIndex) # mypy complaint fix
294+
if categories._is_num_index():
295+
assert isinstance(categories, NumericIndex) # mypy complaint fix
296296
try:
297-
cat._validate_dtype(dtype)
297+
categories._validate_dtype(dtype)
298298
except ValueError:
299299
pass
300300
else:
301301
new_values = self._data.astype(dtype, copy=copy)
302302
# pass copy=False because any copying has been done in the
303303
# _data.astype call above
304-
return type(cat)(new_values, name=self.name, copy=False)
304+
return type(categories)(new_values, name=self.name, copy=False)
305305

306306
return super().astype(dtype, copy=copy)
307307

pandas/core/indexes/numeric.py

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from pandas._typing import (
1616
Dtype,
1717
DtypeObj,
18+
final,
1819
)
1920
from pandas.util._decorators import (
2021
cache_readonly,
@@ -278,6 +279,15 @@ def _assert_safe_casting(cls, data, subarr):
278279
"""
279280
pass
280281

282+
@final
283+
@cache_readonly
284+
def _can_hold_na(self) -> bool:
285+
if is_integer_dtype(self.dtype):
286+
return False
287+
else:
288+
return True
289+
290+
@final
281291
@property
282292
def _is_all_dates(self) -> bool:
283293
"""

0 commit comments

Comments
 (0)