Skip to content

Commit 6635a60

Browse files
committed
_is_num_index -> _is_numeric_index + Index.union
1 parent e580b78 commit 6635a60

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

@@ -2418,7 +2422,7 @@ def _is_multi(self) -> bool:
24182422

24192423
@final
24202424
@classmethod
2421-
def _is_num_index(cls) -> bool:
2425+
def _is_numeric_index(cls) -> bool:
24222426
"""
24232427
Check if this is a NumericIndex, but *not* Int64Index, UInt64Index, FloatIndex.
24242428
@@ -5514,7 +5518,7 @@ def map(self, mapper, na_action=None):
55145518
# empty
55155519
attributes["dtype"] = self.dtype
55165520

5517-
if self._is_num_index() and is_numeric_dtype(new_values.dtype):
5521+
if self._is_numeric_index() and is_numeric_dtype(new_values.dtype):
55185522
return NumericIndex(new_values, **attributes)
55195523

55205524
return Index(new_values, **attributes)

pandas/core/indexes/category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def astype(self, dtype, copy: bool = True) -> Index:
297297
# the super method always returns Int64Index, UInt64Index and Float64Index
298298
# but if e.g. the categories are a NumIndex with dtype float32, we want to
299299
# return an index with the same dtype as self.categories.
300-
if categories._is_num_index():
300+
if categories._is_numeric_index():
301301
assert isinstance(categories, NumericIndex) # mypy complaint fix
302302
try:
303303
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
@@ -664,7 +664,7 @@ def test_map_dictlike(self, mapper, simple_index):
664664
tm.assert_index_equal(result, expected)
665665

666666
# empty mappable
667-
if idx._is_num_index():
667+
if idx._is_numeric_index():
668668
new_index_cls = NumericIndex
669669
else:
670670
new_index_cls = Float64Index

pandas/tests/indexes/test_base.py

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

0 commit comments

Comments
 (0)