@@ -74,8 +74,8 @@ class NumericIndex(Index):
74
74
Notes
75
75
-----
76
76
An NumericIndex instance can **only** contain numpy int64/32/16/8, uint64/32/16/8 or
77
- float64/32/16 dtype. In particular, ``NumericIndex`` *can not* hold Pandas numeric
78
- dtypes (:class:`Int64Dtype`, :class:`Int32Dtype` etc.).
77
+ float64/32 dtype. In particular, ``NumericIndex`` *can not* hold numpy float16
78
+ dtype or Pandas numeric dtypes (:class:`Int64Dtype`, :class:`Int32Dtype` etc.).
79
79
"""
80
80
81
81
_typ = "numericindex"
@@ -174,6 +174,10 @@ def _ensure_array(cls, data, dtype, copy: bool):
174
174
raise ValueError ("Index data must be 1-dimensional" )
175
175
176
176
subarr = np .asarray (subarr )
177
+ if subarr .dtype == "float16" :
178
+ # float16 not supported (no indexing engine)
179
+ subarr = subarr .astype ("float32" )
180
+
177
181
return subarr
178
182
179
183
@classmethod
@@ -198,6 +202,9 @@ def _ensure_dtype(cls, dtype: Dtype | None) -> np.dtype | None:
198
202
return cls ._default_dtype
199
203
200
204
dtype = pandas_dtype (dtype )
205
+ if dtype == np .float16 :
206
+ # float16 not supported (no indexing engine)
207
+ dtype = np .dtype (np .float32 )
201
208
assert isinstance (dtype , np .dtype )
202
209
203
210
if cls ._is_backward_compat_public_numeric_index :
0 commit comments