Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ class Index(IndexOpsMixin, PandasObject):

The basic object storing axis labels for all pandas objects.

.. versionchanged:: 2.0.0

Index can hold all numpy numeric dtypes (except float16). Previously only
int64/uint64/float64 dtypes were accepted.

Parameters
----------
data : array-like (1-dimensional)
Expand Down Expand Up @@ -315,7 +320,8 @@ class Index(IndexOpsMixin, PandasObject):

Notes
-----
An Index instance can **only** contain hashable objects
An Index instance can **only** contain hashable objects.
An Index instance *can not* hold numpy float16 dtype.

Examples
--------
Expand All @@ -324,6 +330,9 @@ class Index(IndexOpsMixin, PandasObject):

>>> pd.Index(list('abc'))
Index(['a', 'b', 'c'], dtype='object')

>>> pd.Index([1, 2, 3], dtype="uint8")
NumericIndex([1, 2, 3], dtype='uint8')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be updated later? (when NumericIndex is gone?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I`ll do a ctrl-f to clean up any cruft left at the end.

"""

# To hand over control to subclasses
Expand Down Expand Up @@ -400,7 +409,10 @@ def _outer_indexer(
_no_setting_name: bool = False
_comparables: list[str] = ["name"]
_attributes: list[str] = ["name"]
_can_hold_strings: bool = True

@cache_readonly
def _can_hold_strings(self) -> bool:
return not is_numeric_dtype(self)

_engine_types: dict[np.dtype | ExtensionDtype, type[libindex.IndexEngine]] = {
np.dtype(np.int8): libindex.Int8Engine,
Expand Down
40 changes: 0 additions & 40 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,6 @@


class NumericIndex(Index):
"""
Immutable numeric sequence used for indexing and alignment.

The basic object storing axis labels for all pandas objects.
NumericIndex is a special case of `Index` with purely numpy int/uint/float labels.

.. versionadded:: 1.4.0

Parameters
----------
data : array-like (1-dimensional)
dtype : NumPy dtype (default: None)
copy : bool
Make a copy of input ndarray.
name : object
Name to be stored in the index.

Attributes
----------
None

Methods
-------
None

See Also
--------
Index : The base pandas Index type.

Notes
-----
An NumericIndex instance can **only** contain numpy int64/32/16/8, uint64/32/16/8 or
float64/32 dtype. In particular, ``NumericIndex`` *can not* hold numpy float16
dtype or Pandas numeric dtypes (:class:`Int64Dtype`, :class:`Int32Dtype` etc.).
"""

_typ = "numericindex"
_default_dtype: np.dtype | None = None
_can_hold_strings = False

def __new__(
cls, data=None, dtype: Dtype | None = None, copy: bool = False, name=None
) -> NumericIndex:
Expand Down