1
- import operator
2
1
from typing import Any
3
2
import warnings
4
3
5
4
import numpy as np
6
5
7
6
from pandas ._libs import index as libindex , lib
8
7
from pandas ._typing import Dtype , Label
9
- from pandas .util ._decorators import cache_readonly , doc
8
+ from pandas .util ._decorators import doc
10
9
11
10
from pandas .core .dtypes .cast import astype_nansafe
12
11
from pandas .core .dtypes .common import (
@@ -188,18 +187,6 @@ def _union(self, other, sort):
188
187
else :
189
188
return super ()._union (other , sort )
190
189
191
- def _cmp_method (self , other , op ):
192
- if self .is_ (other ): # fastpath
193
- if op in {operator .eq , operator .le , operator .ge }:
194
- arr = np .ones (len (self ), dtype = bool )
195
- if self ._can_hold_na :
196
- arr [self .isna ()] = False
197
- return arr
198
- elif op in {operator .ne , operator .lt , operator .gt }:
199
- return np .zeros (len (self ), dtype = bool )
200
-
201
- return super ()._cmp_method (other , op )
202
-
203
190
204
191
_num_index_shared_docs [
205
192
"class_descr"
@@ -243,6 +230,20 @@ class IntegerIndex(NumericIndex):
243
230
"""
244
231
245
232
_default_dtype : np .dtype
233
+ _can_hold_na = False
234
+
235
+ @classmethod
236
+ def _assert_safe_casting (cls , data , subarr ):
237
+ """
238
+ Ensure incoming data can be represented with matching signed-ness.
239
+ """
240
+ if data .dtype .kind != cls ._default_dtype .kind :
241
+ if not np .array_equal (data , subarr ):
242
+ raise TypeError ("Unsafe NumPy casting, you must explicitly cast" )
243
+
244
+ def _can_union_without_object_cast (self , other ) -> bool :
245
+ # See GH#26778, further casting may occur in NumericIndex._union
246
+ return other .dtype == "f8" or other .dtype == self .dtype
246
247
247
248
def __contains__ (self , key ) -> bool :
248
249
"""
@@ -278,23 +279,9 @@ class Int64Index(IntegerIndex):
278
279
__doc__ = _num_index_shared_docs ["class_descr" ] % _int64_descr_args
279
280
280
281
_typ = "int64index"
281
- _can_hold_na = False
282
282
_engine_type = libindex .Int64Engine
283
283
_default_dtype = np .dtype (np .int64 )
284
284
285
- @classmethod
286
- def _assert_safe_casting (cls , data , subarr ):
287
- """
288
- Ensure incoming data can be represented as ints.
289
- """
290
- if not issubclass (data .dtype .type , np .signedinteger ):
291
- if not np .array_equal (data , subarr ):
292
- raise TypeError ("Unsafe NumPy casting, you must explicitly cast" )
293
-
294
- def _can_union_without_object_cast (self , other ) -> bool :
295
- # See GH#26778, further casting may occur in NumericIndex._union
296
- return other .dtype == "f8" or other .dtype == self .dtype
297
-
298
285
299
286
_uint64_descr_args = dict (
300
287
klass = "UInt64Index" , ltype = "unsigned integer" , dtype = "uint64" , extra = ""
@@ -305,7 +292,6 @@ class UInt64Index(IntegerIndex):
305
292
__doc__ = _num_index_shared_docs ["class_descr" ] % _uint64_descr_args
306
293
307
294
_typ = "uint64index"
308
- _can_hold_na = False
309
295
_engine_type = libindex .UInt64Engine
310
296
_default_dtype = np .dtype (np .uint64 )
311
297
@@ -324,21 +310,6 @@ def _convert_arr_indexer(self, keyarr):
324
310
325
311
return com .asarray_tuplesafe (keyarr , dtype = dtype )
326
312
327
- # ----------------------------------------------------------------
328
-
329
- @classmethod
330
- def _assert_safe_casting (cls , data , subarr ):
331
- """
332
- Ensure incoming data can be represented as uints.
333
- """
334
- if not issubclass (data .dtype .type , np .unsignedinteger ):
335
- if not np .array_equal (data , subarr ):
336
- raise TypeError ("Unsafe NumPy casting, you must explicitly cast" )
337
-
338
- def _can_union_without_object_cast (self , other ) -> bool :
339
- # See GH#26778, further casting may occur in NumericIndex._union
340
- return other .dtype == "f8" or other .dtype == self .dtype
341
-
342
313
343
314
_float64_descr_args = dict (
344
315
klass = "Float64Index" , dtype = "float64" , ltype = "float" , extra = ""
@@ -350,7 +321,7 @@ class Float64Index(NumericIndex):
350
321
351
322
_typ = "float64index"
352
323
_engine_type = libindex .Float64Engine
353
- _default_dtype = np .float64
324
+ _default_dtype = np .dtype ( np . float64 )
354
325
355
326
@property
356
327
def inferred_type (self ) -> str :
@@ -429,10 +400,6 @@ def __contains__(self, other: Any) -> bool:
429
400
430
401
return is_float (other ) and np .isnan (other ) and self .hasnans
431
402
432
- @cache_readonly
433
- def is_unique (self ) -> bool :
434
- return super ().is_unique and self ._nan_idxs .size < 2
435
-
436
403
def _can_union_without_object_cast (self , other ) -> bool :
437
404
# See GH#26778, further casting may occur in NumericIndex._union
438
405
return is_numeric_dtype (other .dtype )
0 commit comments