@@ -269,10 +269,6 @@ def _outer_indexer(self, left, right):
269
269
# would we like our indexing holder to defer to us
270
270
_defer_to_indexing = False
271
271
272
- # prioritize current class for _shallow_copy_with_infer,
273
- # used to infer integers as datetime-likes
274
- _infer_as_myclass = False
275
-
276
272
_engine_type = libindex .ObjectEngine
277
273
# whether we support partial string indexing. Overridden
278
274
# in DatetimeIndex and PeriodIndex
@@ -440,10 +436,6 @@ def __new__(
440
436
_simple_new), but fills caller's metadata otherwise specified. Passed
441
437
kwargs will overwrite corresponding metadata.
442
438
443
- - _shallow_copy_with_infer: It returns new Index inferring its type
444
- from passed values. It fills caller's metadata otherwise specified as the
445
- same as _shallow_copy.
446
-
447
439
See each method's docstring.
448
440
"""
449
441
@@ -516,35 +508,6 @@ def _shallow_copy(self, values=None, name: Label = no_default):
516
508
result ._cache = cache
517
509
return result
518
510
519
- def _shallow_copy_with_infer (self , values , ** kwargs ):
520
- """
521
- Create a new Index inferring the class with passed value, don't copy
522
- the data, use the same object attributes with passed in attributes
523
- taking precedence.
524
-
525
- *this is an internal non-public method*
526
-
527
- Parameters
528
- ----------
529
- values : the values to create the new Index, optional
530
- kwargs : updates the default attributes for this Index
531
- """
532
- attributes = self ._get_attributes_dict ()
533
- attributes .update (kwargs )
534
- attributes ["copy" ] = False
535
- if not len (values ) and "dtype" not in kwargs :
536
- # TODO: what if hasattr(values, "dtype")?
537
- attributes ["dtype" ] = self .dtype
538
- if self ._infer_as_myclass :
539
- try :
540
- return self ._constructor (values , ** attributes )
541
- except (TypeError , ValueError ):
542
- pass
543
-
544
- # Remove tz so Index will try non-DatetimeIndex inference
545
- attributes .pop ("tz" , None )
546
- return Index (values , ** attributes )
547
-
548
511
def is_ (self , other ) -> bool :
549
512
"""
550
513
More flexible, faster check like ``is`` but that works through views.
@@ -2809,11 +2772,7 @@ def symmetric_difference(self, other, result_name=None, sort=None):
2809
2772
except TypeError :
2810
2773
pass
2811
2774
2812
- attribs = self ._get_attributes_dict ()
2813
- attribs ["name" ] = result_name
2814
- if "freq" in attribs :
2815
- attribs ["freq" ] = None
2816
- return self ._shallow_copy_with_infer (the_diff , ** attribs )
2775
+ return Index (the_diff , dtype = self .dtype , name = result_name )
2817
2776
2818
2777
def _assert_can_do_setop (self , other ):
2819
2778
if not is_list_like (other ):
@@ -3387,7 +3346,7 @@ def _reindex_non_unique(self, target):
3387
3346
new_indexer = np .arange (len (self .take (indexer )))
3388
3347
new_indexer [~ check ] = - 1
3389
3348
3390
- new_index = self . _shallow_copy_with_infer (new_labels )
3349
+ new_index = Index (new_labels , name = self . name )
3391
3350
return new_index , indexer , new_indexer
3392
3351
3393
3352
# --------------------------------------------------------------------
@@ -3936,7 +3895,7 @@ def where(self, cond, other=None):
3936
3895
# it's float) if there are NaN values in our output.
3937
3896
dtype = None
3938
3897
3939
- return self . _shallow_copy_with_infer (values , dtype = dtype )
3898
+ return Index (values , dtype = dtype , name = self . name )
3940
3899
3941
3900
# construction helpers
3942
3901
@classmethod
@@ -4166,7 +4125,8 @@ def _concat_same_dtype(self, to_concat, name):
4166
4125
4167
4126
to_concat = [x ._values if isinstance (x , Index ) else x for x in to_concat ]
4168
4127
4169
- return self ._shallow_copy_with_infer (np .concatenate (to_concat ), ** attribs )
4128
+ res_values = np .concatenate (to_concat )
4129
+ return Index (res_values , name = name )
4170
4130
4171
4131
def putmask (self , mask , value ):
4172
4132
"""
@@ -5208,7 +5168,7 @@ def insert(self, loc: int, item):
5208
5168
arr = np .asarray (self )
5209
5169
item = self ._coerce_scalar_to_index (item )._values
5210
5170
idx = np .concatenate ((arr [:loc ], item , arr [loc :]))
5211
- return self . _shallow_copy_with_infer (idx )
5171
+ return Index (idx , name = self . name )
5212
5172
5213
5173
def drop (self , labels , errors : str_t = "raise" ):
5214
5174
"""
0 commit comments