Skip to content

Commit 2701118

Browse files
committed
_is_num_index -> _is_numeric_index + Index.union
1 parent 85fb760 commit 2701118

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

pandas/core/indexes/base.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,11 @@ def __new__(
439439
return Index._simple_new(data, name=name)
440440

441441
# index-like
442-
elif isinstance(data, NumericIndex) and data._is_num_index() and dtype is None:
442+
elif (
443+
isinstance(data, NumericIndex)
444+
and data._is_numeric_index()
445+
and dtype is None
446+
):
443447
return NumericIndex(data, name=name, copy=copy)
444448
elif isinstance(data, (np.ndarray, Index, ABCSeries)):
445449

@@ -2420,7 +2424,7 @@ def _is_multi(self) -> bool:
24202424

24212425
@final
24222426
@classmethod
2423-
def _is_num_index(cls) -> bool:
2427+
def _is_numeric_index(cls) -> bool:
24242428
"""
24252429
Check if this is a NumericIndex, but *not* Int64Index, UInt64Index, FloatIndex.
24262430
@@ -5665,7 +5669,7 @@ def map(self, mapper, na_action=None):
56655669
# empty
56665670
attributes["dtype"] = self.dtype
56675671

5668-
if self._is_num_index() and is_numeric_dtype(new_values.dtype):
5672+
if self._is_numeric_index() and is_numeric_dtype(new_values.dtype):
56695673
return NumericIndex(new_values, **attributes)
56705674

56715675
return Index(new_values, **attributes)

pandas/core/indexes/category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def astype(self, dtype, copy: bool = True) -> Index:
290290
# the super method always returns Int64Index, UInt64Index and Float64Index
291291
# but if e.g. the categories are a NumIndex with dtype float32, we want to
292292
# return an index with the same dtype as self.categories.
293-
if categories._is_num_index():
293+
if categories._is_numeric_index():
294294
assert isinstance(categories, NumericIndex) # mypy complaint fix
295295
try:
296296
categories._validate_dtype(dtype)

pandas/tests/base/test_unique.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_unique(index_or_series_obj):
2525
expected = pd.MultiIndex.from_tuples(unique_values)
2626
expected.names = obj.names
2727
tm.assert_index_equal(result, expected, exact=True)
28-
elif isinstance(obj, pd.Index) and obj._is_num_index():
28+
elif isinstance(obj, pd.Index) and obj._is_numeric_index():
2929
expected = NumericIndex(unique_values, dtype=obj.dtype)
3030
tm.assert_index_equal(result, expected, exact=True)
3131
elif isinstance(obj, pd.Index):
@@ -66,7 +66,7 @@ def test_unique_null(null_obj, index_or_series_obj):
6666
unique_values_not_null = [val for val in unique_values_raw if not pd.isnull(val)]
6767
unique_values = [null_obj] + unique_values_not_null
6868

69-
if isinstance(obj, pd.Index) and obj._is_num_index():
69+
if isinstance(obj, pd.Index) and obj._is_numeric_index():
7070
expected = NumericIndex(unique_values, dtype=obj.dtype)
7171
tm.assert_index_equal(result, expected, exact=True)
7272
elif isinstance(obj, pd.Index):

pandas/tests/indexes/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ def test_map_dictlike(self, mapper, simple_index):
665665
tm.assert_index_equal(result, expected)
666666

667667
# empty mappable
668-
if idx._is_num_index():
668+
if idx._is_numeric_index():
669669
new_index_cls = NumericIndex
670670
else:
671671
new_index_cls = Float64Index

pandas/tests/indexes/test_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ def test_map_dictlike(self, index, mapper):
714714
if index.empty:
715715
# to match proper result coercion for uints
716716
expected = Index([])
717-
elif index._is_num_index():
717+
elif index._is_numeric_index():
718718
expected = type(index)(np.arange(len(index), 0, -1), dtype=index.dtype)
719719
else:
720720
expected = Index(np.arange(len(index), 0, -1))

0 commit comments

Comments
 (0)