Skip to content

Commit 3922be1

Browse files
committed
_is_num_index -> _is_numeric_index + Index.union
1 parent 75dd0a9 commit 3922be1

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
@@ -438,7 +438,11 @@ def __new__(
438438
return Index._simple_new(data, name=name)
439439

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

@@ -2426,7 +2430,7 @@ def _is_multi(self) -> bool:
24262430

24272431
@final
24282432
@classmethod
2429-
def _is_num_index(cls) -> bool:
2433+
def _is_numeric_index(cls) -> bool:
24302434
"""
24312435
Check if this is a NumericIndex, but *not* Int64Index, UInt64Index, FloatIndex.
24322436
@@ -5763,7 +5767,7 @@ def map(self, mapper, na_action=None):
57635767
# empty
57645768
attributes["dtype"] = self.dtype
57655769

5766-
if self._is_num_index() and is_numeric_dtype(new_values.dtype):
5770+
if self._is_numeric_index() and is_numeric_dtype(new_values.dtype):
57675771
return NumericIndex(new_values, **attributes)
57685772

57695773
return Index(new_values, **attributes)

pandas/core/indexes/category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def astype(self, dtype, copy: bool = True) -> Index:
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 categories._is_num_index():
294+
if categories._is_numeric_index():
295295
assert isinstance(categories, NumericIndex) # mypy complaint fix
296296
try:
297297
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
@@ -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)