Skip to content

Commit 9f2138c

Browse files
committed
make attribute name clearer
1 parent 5ba434d commit 9f2138c

File tree

8 files changed

+24
-16
lines changed

8 files changed

+24
-16
lines changed

pandas/core/indexes/base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def _outer_indexer(
362362

363363
# Whether this index is a NumericIndex, but not a Int64Index, Float64Index,
364364
# UInt64Index or RangeIndex. Needed for backwards compat. Remove in pandas 2.0.
365-
_is_numeric_index: bool = False
365+
_is_backward_compat_public_numeric_index: bool = False
366366

367367
_engine_type: type[libindex.IndexEngine] = libindex.ObjectEngine
368368
# whether we support partial string indexing. Overridden
@@ -441,7 +441,11 @@ def __new__(
441441
return Index._simple_new(data, name=name)
442442

443443
# index-like
444-
elif isinstance(data, Index) and data._is_numeric_index and dtype is None:
444+
elif (
445+
isinstance(data, Index)
446+
and data._is_backward_compat_public_numeric_index
447+
and dtype is None
448+
):
445449
return data._constructor(data, name=name, copy=copy)
446450
elif isinstance(data, (np.ndarray, Index, ABCSeries)):
447451

@@ -5743,7 +5747,9 @@ def map(self, mapper, na_action=None):
57435747
# empty
57445748
attributes["dtype"] = self.dtype
57455749

5746-
if self._is_numeric_index and is_numeric_dtype(new_values.dtype):
5750+
if self._is_backward_compat_public_numeric_index and is_numeric_dtype(
5751+
new_values.dtype
5752+
):
57475753
return self._constructor(new_values, **attributes)
57485754

57495755
return Index(new_values, **attributes)

pandas/core/indexes/category.py

Lines changed: 1 addition & 1 deletion
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 the categories are a NumericIndex with dtype float32, we want to
293293
# return an index with the same dtype as self.categories.
294-
if categories._is_numeric_index:
294+
if categories._is_backward_compat_public_numeric_index:
295295
assert isinstance(categories, NumericIndex) # mypy complaint fix
296296
try:
297297
categories._validate_dtype(dtype)

pandas/core/indexes/numeric.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class NumericIndex(Index):
9797
)
9898
_is_numeric_dtype = True
9999
_can_hold_strings = False
100-
_is_numeric_index: bool = True
100+
_is_backward_compat_public_numeric_index: bool = True
101101

102102
@cache_readonly
103103
def _can_hold_na(self) -> bool:
@@ -206,9 +206,11 @@ def _ensure_dtype(cls, dtype: Dtype | None) -> np.dtype | None:
206206
dtype = pandas_dtype(dtype)
207207
assert isinstance(dtype, np.dtype)
208208

209-
if cls._is_numeric_index: # NumericIndex
209+
if cls._is_backward_compat_public_numeric_index:
210+
# dtype for NumericIndex
210211
return dtype
211-
else: # Int64Index, UInt64Index etc.
212+
else:
213+
# dtype for Int64Index, UInt64Index etc. Needed for backwards compat.
212214
return cls._default_dtype
213215

214216
def __contains__(self, key) -> bool:
@@ -244,7 +246,7 @@ def astype(self, dtype, copy=True):
244246
return Int64Index(arr, name=self.name)
245247
else:
246248
return NumericIndex(arr, name=self.name, dtype=dtype)
247-
elif self._is_numeric_index:
249+
elif self._is_backward_compat_public_numeric_index:
248250
if not is_extension_array_dtype(dtype) and is_numeric_dtype(dtype):
249251
return self._constructor(self, dtype=dtype, copy=copy)
250252

@@ -356,7 +358,7 @@ class IntegerIndex(NumericIndex):
356358
This is an abstract class for Int64Index, UInt64Index.
357359
"""
358360

359-
_is_numeric_index: bool = False
361+
_is_backward_compat_public_numeric_index: bool = False
360362

361363
@property
362364
def asi8(self) -> np.ndarray:
@@ -422,4 +424,4 @@ class Float64Index(NumericIndex):
422424
_engine_type = libindex.Float64Engine
423425
_default_dtype = np.dtype(np.float64)
424426
_dtype_validation_metadata = (is_float_dtype, "float")
425-
_is_numeric_index: bool = False
427+
_is_backward_compat_public_numeric_index: bool = False

pandas/core/indexes/range.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class RangeIndex(NumericIndex):
101101
_engine_type = libindex.Int64Engine
102102
_dtype_validation_metadata = (is_signed_integer_dtype, "signed integer")
103103
_range: range
104-
_is_numeric_index: bool = False
104+
_is_backward_compat_public_numeric_index: bool = False
105105

106106
# --------------------------------------------------------------------
107107
# Constructors

pandas/tests/base/test_unique.py

Lines changed: 2 additions & 2 deletions
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_numeric_index:
28+
elif isinstance(obj, pd.Index) and obj._is_backward_compat_public_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_numeric_index:
69+
if isinstance(obj, pd.Index) and obj._is_backward_compat_public_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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def test_map_dictlike(self, mapper, simple_index):
666666
tm.assert_index_equal(result, expected)
667667

668668
# empty mappable
669-
if idx._is_numeric_index:
669+
if idx._is_backward_compat_public_numeric_index:
670670
new_index_cls = NumericIndex
671671
else:
672672
new_index_cls = Float64Index

pandas/tests/indexes/test_any_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_mutability(index):
5151
def test_map_identity_mapping(index):
5252
# GH#12766
5353
result = index.map(lambda x: x)
54-
if index._is_numeric_index:
54+
if index._is_backward_compat_public_numeric_index:
5555
if is_float_dtype(index.dtype):
5656
expected = index.astype(np.float64)
5757
elif index.dtype == np.uint64:

pandas/tests/indexes/test_base.py

Lines changed: 1 addition & 1 deletion
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_numeric_index:
717+
elif index._is_backward_compat_public_numeric_index:
718718
if is_float_dtype(index.dtype):
719719
exp_dtype = np.float64
720720
else:

0 commit comments

Comments
 (0)