47
47
from pandas .core .construction import extract_array
48
48
import pandas .core .indexes .base as ibase
49
49
from pandas .core .indexes .base import maybe_extract_name
50
- from pandas .core .indexes .numeric import (
51
- Float64Index ,
52
- Int64Index ,
53
- NumericIndex ,
54
- )
50
+ from pandas .core .indexes .numeric import NumericIndex
55
51
from pandas .core .ops .common import unpack_zerodim_and_defer
56
52
57
53
if TYPE_CHECKING :
@@ -64,8 +60,8 @@ class RangeIndex(NumericIndex):
64
60
"""
65
61
Immutable Index implementing a monotonic integer range.
66
62
67
- RangeIndex is a memory-saving special case of Int64Index limited to
68
- representing monotonic ranges. Using RangeIndex may in some instances
63
+ RangeIndex is a memory-saving special case of an Index limited to representing
64
+ monotonic ranges with a 64-bit dtype . Using RangeIndex may in some instances
69
65
improve computing speed.
70
66
71
67
This is the default index type used
@@ -97,7 +93,6 @@ class RangeIndex(NumericIndex):
97
93
See Also
98
94
--------
99
95
Index : The base pandas Index type.
100
- Int64Index : Index of int64 data.
101
96
"""
102
97
103
98
_typ = "rangeindex"
@@ -185,7 +180,7 @@ def _simple_new( # type: ignore[override]
185
180
186
181
# --------------------------------------------------------------------
187
182
188
- # error: Return type "Type[Int64Index ]" of "_constructor" incompatible with return
183
+ # error: Return type "Type[NumericIndex ]" of "_constructor" incompatible with return
189
184
# type "Type[RangeIndex]" in supertype "Index"
190
185
@cache_readonly
191
186
def _constructor (self ) -> type [NumericIndex ]: # type: ignore[override]
@@ -331,7 +326,7 @@ def inferred_type(self) -> str:
331
326
# --------------------------------------------------------------------
332
327
# Indexing Methods
333
328
334
- @doc (Int64Index .get_loc )
329
+ @doc (NumericIndex .get_loc )
335
330
def get_loc (self , key ):
336
331
if is_integer (key ) or (is_float (key ) and key .is_integer ()):
337
332
new_key = int (key )
@@ -377,32 +372,32 @@ def _get_indexer(
377
372
def tolist (self ) -> list [int ]:
378
373
return list (self ._range )
379
374
380
- @doc (Int64Index .__iter__ )
375
+ @doc (NumericIndex .__iter__ )
381
376
def __iter__ (self ) -> Iterator [int ]:
382
377
yield from self ._range
383
378
384
- @doc (Int64Index ._shallow_copy )
379
+ @doc (NumericIndex ._shallow_copy )
385
380
def _shallow_copy (self , values , name : Hashable = no_default ):
386
381
name = self .name if name is no_default else name
387
382
388
383
if values .dtype .kind == "f" :
389
- return Float64Index (values , name = name )
384
+ return NumericIndex (values , name = name , dtype = np . float64 )
390
385
# GH 46675 & 43885: If values is equally spaced, return a
391
- # more memory-compact RangeIndex instead of Int64Index
386
+ # more memory-compact RangeIndex instead of Index with 64-bit dtype
392
387
unique_diffs = unique_deltas (values )
393
388
if len (unique_diffs ) == 1 and unique_diffs [0 ] != 0 :
394
389
diff = unique_diffs [0 ]
395
390
new_range = range (values [0 ], values [- 1 ] + diff , diff )
396
391
return type (self )._simple_new (new_range , name = name )
397
392
else :
398
- return Int64Index ._simple_new (values , name = name )
393
+ return NumericIndex ._simple_new (values , name = name )
399
394
400
395
def _view (self : RangeIndex ) -> RangeIndex :
401
396
result = type (self )._simple_new (self ._range , name = self ._name )
402
397
result ._cache = self ._cache
403
398
return result
404
399
405
- @doc (Int64Index .copy )
400
+ @doc (NumericIndex .copy )
406
401
def copy (self , name : Hashable = None , deep : bool = False ):
407
402
name = self ._validate_names (name = name , deep = deep )[0 ]
408
403
new_index = self ._rename (name = name )
@@ -517,7 +512,6 @@ def _intersection(self, other: Index, sort: bool = False):
517
512
# caller is responsible for checking self and other are both non-empty
518
513
519
514
if not isinstance (other , RangeIndex ):
520
- # Int64Index
521
515
return super ()._intersection (other , sort = sort )
522
516
523
517
first = self ._range [::- 1 ] if self .step < 0 else self ._range
@@ -604,10 +598,10 @@ def _union(self, other: Index, sort):
604
598
sort : False or None, default None
605
599
Whether to sort (monotonically increasing) the resulting index.
606
600
``sort=None`` returns a ``RangeIndex`` if possible or a sorted
607
- ``Int64Index`` if not.
601
+ ``Index`` with a int64 dtype if not.
608
602
``sort=False`` can return a ``RangeIndex`` if self is monotonically
609
603
increasing and other is fully contained in self. Otherwise, returns
610
- an unsorted ``Int64Index``
604
+ an unsorted ``Index`` with an int64 dtype.
611
605
612
606
Returns
613
607
-------
@@ -819,9 +813,9 @@ def _concat(self, indexes: list[Index], name: Hashable) -> Index:
819
813
Overriding parent method for the case of all RangeIndex instances.
820
814
821
815
When all members of "indexes" are of type RangeIndex: result will be
822
- RangeIndex if possible, Int64Index otherwise. E.g.:
816
+ RangeIndex if possible, Index with a int64 dtype otherwise. E.g.:
823
817
indexes = [RangeIndex(3), RangeIndex(3, 6)] -> RangeIndex(6)
824
- indexes = [RangeIndex(3), RangeIndex(4, 6)] -> Int64Index ([0,1,2,4,5])
818
+ indexes = [RangeIndex(3), RangeIndex(4, 6)] -> Index ([0,1,2,4,5], dtype='int64' )
825
819
"""
826
820
if not all (isinstance (x , RangeIndex ) for x in indexes ):
827
821
return super ()._concat (indexes , name )
@@ -848,7 +842,7 @@ def _concat(self, indexes: list[Index], name: Hashable) -> Index:
848
842
# First non-empty index had only one element
849
843
if rng .start == start :
850
844
values = np .concatenate ([x ._values for x in rng_indexes ])
851
- result = Int64Index (values )
845
+ result = self . _constructor (values )
852
846
return result .rename (name )
853
847
854
848
step = rng .start - start
@@ -857,7 +851,9 @@ def _concat(self, indexes: list[Index], name: Hashable) -> Index:
857
851
next_ is not None and rng .start != next_
858
852
)
859
853
if non_consecutive :
860
- result = Int64Index (np .concatenate ([x ._values for x in rng_indexes ]))
854
+ result = self ._constructor (
855
+ np .concatenate ([x ._values for x in rng_indexes ])
856
+ )
861
857
return result .rename (name )
862
858
863
859
if step is not None :
@@ -905,7 +901,6 @@ def __getitem__(self, key):
905
901
"and integer or boolean "
906
902
"arrays are valid indices"
907
903
)
908
- # fall back to Int64Index
909
904
return super ().__getitem__ (key )
910
905
911
906
def _getitem_slice (self : RangeIndex , slobj : slice ) -> RangeIndex :
@@ -1010,15 +1005,14 @@ def _arith_method(self, other, op):
1010
1005
res_name = ops .get_op_result_name (self , other )
1011
1006
result = type (self )(rstart , rstop , rstep , name = res_name )
1012
1007
1013
- # for compat with numpy / Int64Index
1008
+ # for compat with numpy / Index with int64 dtype
1014
1009
# even if we can represent as a RangeIndex, return
1015
- # as a Float64Index if we have float-like descriptors
1010
+ # as a float64 Index if we have float-like descriptors
1016
1011
if not all (is_integer (x ) for x in [rstart , rstop , rstep ]):
1017
1012
result = result .astype ("float64" )
1018
1013
1019
1014
return result
1020
1015
1021
1016
except (ValueError , TypeError , ZeroDivisionError ):
1022
- # Defer to Int64Index implementation
1023
1017
# test_arithmetic_explicit_conversions
1024
1018
return super ()._arith_method (other , op )
0 commit comments