@@ -288,6 +288,11 @@ class Index(IndexOpsMixin, PandasObject):
288
288
289
289
The basic object storing axis labels for all pandas objects.
290
290
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
+
291
296
Parameters
292
297
----------
293
298
data : array-like (1-dimensional)
@@ -315,7 +320,8 @@ class Index(IndexOpsMixin, PandasObject):
315
320
316
321
Notes
317
322
-----
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.
319
325
320
326
Examples
321
327
--------
@@ -324,6 +330,9 @@ class Index(IndexOpsMixin, PandasObject):
324
330
325
331
>>> pd.Index(list('abc'))
326
332
Index(['a', 'b', 'c'], dtype='object')
333
+
334
+ >>> pd.Index([1, 2, 3], dtype="uint8")
335
+ NumericIndex([1, 2, 3], dtype='uint8')
327
336
"""
328
337
329
338
# To hand over control to subclasses
@@ -400,7 +409,10 @@ def _outer_indexer(
400
409
_no_setting_name : bool = False
401
410
_comparables : list [str ] = ["name" ]
402
411
_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 )
404
416
405
417
_engine_types : dict [np .dtype | ExtensionDtype , type [libindex .IndexEngine ]] = {
406
418
np .dtype (np .int8 ): libindex .Int8Engine ,
0 commit comments