@@ -728,13 +728,6 @@ def _format_duplicate_message(self) -> DataFrame:
728728 # --------------------------------------------------------------------
729729 # Index Internals Methods
730730
731- @final
732- def _get_attributes_dict (self ) -> dict [str_t , Any ]:
733- """
734- Return an attributes dict for my class.
735- """
736- return {k : getattr (self , k , None ) for k in self ._attributes }
737-
738731 def _shallow_copy (self : _IndexT , values , name : Hashable = no_default ) -> _IndexT :
739732 """
740733 Create a new Index with the same class as the caller, don't copy the
@@ -859,9 +852,7 @@ def __array_wrap__(self, result, context=None):
859852 if is_bool_dtype (result ) or lib .is_scalar (result ) or np .ndim (result ) > 1 :
860853 return result
861854
862- attrs = self ._get_attributes_dict ()
863- attrs .pop ("freq" , None ) # For DatetimeIndex/TimedeltaIndex
864- return Index (result , ** attrs )
855+ return Index (result , name = self .name )
865856
866857 @cache_readonly
867858 def dtype (self ) -> DtypeObj :
@@ -2493,8 +2484,7 @@ def _is_multi(self) -> bool:
24932484 # Pickle Methods
24942485
24952486 def __reduce__ (self ):
2496- d = {"data" : self ._data }
2497- d .update (self ._get_attributes_dict ())
2487+ d = {"data" : self ._data , "name" : self .name }
24982488 return _new_Index , (type (self ), d ), None
24992489
25002490 # --------------------------------------------------------------------
@@ -5820,29 +5810,29 @@ def map(self, mapper, na_action=None):
58205810
58215811 new_values = self ._map_values (mapper , na_action = na_action )
58225812
5823- attributes = self ._get_attributes_dict ()
5824-
58255813 # we can return a MultiIndex
58265814 if new_values .size and isinstance (new_values [0 ], tuple ):
58275815 if isinstance (self , MultiIndex ):
58285816 names = self .names
5829- elif attributes . get ( " name" ) :
5830- names = [attributes . get ( " name" ) ] * len (new_values [0 ])
5817+ elif self . name :
5818+ names = [self . name ] * len (new_values [0 ])
58315819 else :
58325820 names = None
58335821 return MultiIndex .from_tuples (new_values , names = names )
58345822
5835- attributes [ "copy" ] = False
5823+ dtype = None
58365824 if not new_values .size :
58375825 # empty
5838- attributes [ " dtype" ] = self .dtype
5826+ dtype = self .dtype
58395827
58405828 if self ._is_backward_compat_public_numeric_index and is_numeric_dtype (
58415829 new_values .dtype
58425830 ):
5843- return self ._constructor (new_values , ** attributes )
5831+ return self ._constructor (
5832+ new_values , dtype = dtype , copy = False , name = self .name
5833+ )
58445834
5845- return Index ._with_infer (new_values , ** attributes )
5835+ return Index ._with_infer (new_values , dtype = dtype , copy = False , name = self . name )
58465836
58475837 # TODO: De-duplicate with map, xref GH#32349
58485838 @final
0 commit comments