@@ -728,13 +728,6 @@ def _format_duplicate_message(self) -> DataFrame:
728
728
# --------------------------------------------------------------------
729
729
# Index Internals Methods
730
730
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
-
738
731
def _shallow_copy (self : _IndexT , values , name : Hashable = no_default ) -> _IndexT :
739
732
"""
740
733
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):
859
852
if is_bool_dtype (result ) or lib .is_scalar (result ) or np .ndim (result ) > 1 :
860
853
return result
861
854
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 )
865
856
866
857
@cache_readonly
867
858
def dtype (self ) -> DtypeObj :
@@ -2493,8 +2484,7 @@ def _is_multi(self) -> bool:
2493
2484
# Pickle Methods
2494
2485
2495
2486
def __reduce__ (self ):
2496
- d = {"data" : self ._data }
2497
- d .update (self ._get_attributes_dict ())
2487
+ d = {"data" : self ._data , "name" : self .name }
2498
2488
return _new_Index , (type (self ), d ), None
2499
2489
2500
2490
# --------------------------------------------------------------------
@@ -5820,29 +5810,29 @@ def map(self, mapper, na_action=None):
5820
5810
5821
5811
new_values = self ._map_values (mapper , na_action = na_action )
5822
5812
5823
- attributes = self ._get_attributes_dict ()
5824
-
5825
5813
# we can return a MultiIndex
5826
5814
if new_values .size and isinstance (new_values [0 ], tuple ):
5827
5815
if isinstance (self , MultiIndex ):
5828
5816
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 ])
5831
5819
else :
5832
5820
names = None
5833
5821
return MultiIndex .from_tuples (new_values , names = names )
5834
5822
5835
- attributes [ "copy" ] = False
5823
+ dtype = None
5836
5824
if not new_values .size :
5837
5825
# empty
5838
- attributes [ " dtype" ] = self .dtype
5826
+ dtype = self .dtype
5839
5827
5840
5828
if self ._is_backward_compat_public_numeric_index and is_numeric_dtype (
5841
5829
new_values .dtype
5842
5830
):
5843
- return self ._constructor (new_values , ** attributes )
5831
+ return self ._constructor (
5832
+ new_values , dtype = dtype , copy = False , name = self .name
5833
+ )
5844
5834
5845
- return Index ._with_infer (new_values , ** attributes )
5835
+ return Index ._with_infer (new_values , dtype = dtype , copy = False , name = self . name )
5846
5836
5847
5837
# TODO: De-duplicate with map, xref GH#32349
5848
5838
@final
0 commit comments