Skip to content

Commit 3770dda

Browse files
authored
DEPR: Move NumericIndex doc string + some minor stuff (#51089)
1 parent 0d9fdd4 commit 3770dda

File tree

2 files changed

+14
-42
lines changed

2 files changed

+14
-42
lines changed

pandas/core/indexes/base.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ class Index(IndexOpsMixin, PandasObject):
288288
289289
The basic object storing axis labels for all pandas objects.
290290
291+
.. versionchanged:: 2.0.0
292+
293+
Index can hold all numpy numeric dtypes (except float16). Previously only
294+
int64/uint64/float64 dtypes were accepted.
295+
291296
Parameters
292297
----------
293298
data : array-like (1-dimensional)
@@ -315,7 +320,8 @@ class Index(IndexOpsMixin, PandasObject):
315320
316321
Notes
317322
-----
318-
An Index instance can **only** contain hashable objects
323+
An Index instance can **only** contain hashable objects.
324+
An Index instance *can not* hold numpy float16 dtype.
319325
320326
Examples
321327
--------
@@ -324,6 +330,9 @@ class Index(IndexOpsMixin, PandasObject):
324330
325331
>>> pd.Index(list('abc'))
326332
Index(['a', 'b', 'c'], dtype='object')
333+
334+
>>> pd.Index([1, 2, 3], dtype="uint8")
335+
NumericIndex([1, 2, 3], dtype='uint8')
327336
"""
328337

329338
# To hand over control to subclasses
@@ -400,7 +409,10 @@ def _outer_indexer(
400409
_no_setting_name: bool = False
401410
_comparables: list[str] = ["name"]
402411
_attributes: list[str] = ["name"]
403-
_can_hold_strings: bool = True
412+
413+
@cache_readonly
414+
def _can_hold_strings(self) -> bool:
415+
return not is_numeric_dtype(self)
404416

405417
_engine_types: dict[np.dtype | ExtensionDtype, type[libindex.IndexEngine]] = {
406418
np.dtype(np.int8): libindex.Int8Engine,

pandas/core/indexes/numeric.py

-40
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,6 @@
1212

1313

1414
class NumericIndex(Index):
15-
"""
16-
Immutable numeric sequence used for indexing and alignment.
17-
18-
The basic object storing axis labels for all pandas objects.
19-
NumericIndex is a special case of `Index` with purely numpy int/uint/float labels.
20-
21-
.. versionadded:: 1.4.0
22-
23-
Parameters
24-
----------
25-
data : array-like (1-dimensional)
26-
dtype : NumPy dtype (default: None)
27-
copy : bool
28-
Make a copy of input ndarray.
29-
name : object
30-
Name to be stored in the index.
31-
32-
Attributes
33-
----------
34-
None
35-
36-
Methods
37-
-------
38-
None
39-
40-
See Also
41-
--------
42-
Index : The base pandas Index type.
43-
44-
Notes
45-
-----
46-
An NumericIndex instance can **only** contain numpy int64/32/16/8, uint64/32/16/8 or
47-
float64/32 dtype. In particular, ``NumericIndex`` *can not* hold numpy float16
48-
dtype or Pandas numeric dtypes (:class:`Int64Dtype`, :class:`Int32Dtype` etc.).
49-
"""
50-
51-
_typ = "numericindex"
52-
_default_dtype: np.dtype | None = None
53-
_can_hold_strings = False
54-
5515
def __new__(
5616
cls, data=None, dtype: Dtype | None = None, copy: bool = False, name=None
5717
) -> NumericIndex:

0 commit comments

Comments
 (0)