@@ -269,10 +269,6 @@ def _outer_indexer(self, left, right):
269269 # would we like our indexing holder to defer to us
270270 _defer_to_indexing = False
271271
272- # prioritize current class for _shallow_copy_with_infer,
273- # used to infer integers as datetime-likes
274- _infer_as_myclass = False
275-
276272 _engine_type = libindex .ObjectEngine
277273 # whether we support partial string indexing. Overridden
278274 # in DatetimeIndex and PeriodIndex
@@ -440,10 +436,6 @@ def __new__(
440436 _simple_new), but fills caller's metadata otherwise specified. Passed
441437 kwargs will overwrite corresponding metadata.
442438
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-
447439 See each method's docstring.
448440 """
449441
@@ -516,35 +508,6 @@ def _shallow_copy(self, values=None, name: Label = no_default):
516508 result ._cache = cache
517509 return result
518510
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-
548511 def is_ (self , other ) -> bool :
549512 """
550513 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):
28092772 except TypeError :
28102773 pass
28112774
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 )
28172776
28182777 def _assert_can_do_setop (self , other ):
28192778 if not is_list_like (other ):
@@ -3387,7 +3346,7 @@ def _reindex_non_unique(self, target):
33873346 new_indexer = np .arange (len (self .take (indexer )))
33883347 new_indexer [~ check ] = - 1
33893348
3390- new_index = self . _shallow_copy_with_infer (new_labels )
3349+ new_index = Index (new_labels , name = self . name )
33913350 return new_index , indexer , new_indexer
33923351
33933352 # --------------------------------------------------------------------
@@ -3936,7 +3895,7 @@ def where(self, cond, other=None):
39363895 # it's float) if there are NaN values in our output.
39373896 dtype = None
39383897
3939- return self . _shallow_copy_with_infer (values , dtype = dtype )
3898+ return Index (values , dtype = dtype , name = self . name )
39403899
39413900 # construction helpers
39423901 @classmethod
@@ -4166,7 +4125,8 @@ def _concat_same_dtype(self, to_concat, name):
41664125
41674126 to_concat = [x ._values if isinstance (x , Index ) else x for x in to_concat ]
41684127
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 )
41704130
41714131 def putmask (self , mask , value ):
41724132 """
@@ -5208,7 +5168,7 @@ def insert(self, loc: int, item):
52085168 arr = np .asarray (self )
52095169 item = self ._coerce_scalar_to_index (item )._values
52105170 idx = np .concatenate ((arr [:loc ], item , arr [loc :]))
5211- return self . _shallow_copy_with_infer (idx )
5171+ return Index (idx , name = self . name )
52125172
52135173 def drop (self , labels , errors : str_t = "raise" ):
52145174 """
0 commit comments