@@ -2675,7 +2675,7 @@ def get_indexer_for(self, target, **kwargs):
2675
2675
2676
2676
Parameters
2677
2677
----------
2678
- data : dict
2678
+ data : { dict, DictWithoutMissing}
2679
2679
The dictionary from which to extract the values
2680
2680
2681
2681
Returns
@@ -2727,43 +2727,36 @@ def groupby(self, values):
2727
2727
2728
2728
return result
2729
2729
2730
- def map (self , mapper ):
2731
- """Apply mapper function to an index.
2730
+ def map (self , arg , na_action = None ):
2731
+ """Map values of Series using input correspondence (which can be a
2732
+ dict, Series, or function)
2732
2733
2733
2734
Parameters
2734
2735
----------
2735
- mapper : {callable, dict, Series}
2736
- Function to be applied or input correspondence object.
2737
- dict and Series support new in 0.20.0.
2736
+ arg : function, dict, or Series
2737
+ na_action : {None, 'ignore'}
2738
+ If 'ignore', propagate NA values, without passing them to the
2739
+ mapping function
2738
2740
2739
2741
Returns
2740
2742
-------
2741
- applied : Union[ Index, MultiIndex] , inferred
2743
+ applied : { Index, MultiIndex} , inferred
2742
2744
The output of the mapping function applied to the index.
2743
2745
If the function returns a tuple with more than one element
2744
2746
a MultiIndex will be returned.
2745
2747
2746
2748
"""
2747
- from .multi import MultiIndex
2748
-
2749
- if isinstance (mapper , ABCSeries ):
2750
- indexer = mapper .index .get_indexer (self .values )
2751
- mapped_values = algos .take_1d (mapper .values , indexer )
2752
- elif isinstance (mapper , dict ):
2753
- idx = Index (mapper .keys ())
2754
- data = idx ._get_values_from_dict (mapper )
2755
- indexer = idx .get_indexer (self .values )
2756
- mapped_values = algos .take_1d (data , indexer )
2757
- else :
2758
- mapped_values = self ._arrmap (self .values , mapper )
2759
2749
2750
+ from .multi import MultiIndex
2751
+ new_values = super (Index , self )._map_values (
2752
+ self .values , arg , na_action = na_action )
2760
2753
attributes = self ._get_attributes_dict ()
2761
- if mapped_values .size and isinstance (mapped_values [0 ], tuple ):
2762
- return MultiIndex .from_tuples (mapped_values ,
2754
+ if new_values .size and isinstance (new_values [0 ], tuple ):
2755
+ return MultiIndex .from_tuples (new_values ,
2763
2756
names = attributes .get ('name' ))
2764
2757
2765
2758
attributes ['copy' ] = False
2766
- return Index (mapped_values , ** attributes )
2759
+ return Index (new_values , ** attributes )
2767
2760
2768
2761
def isin (self , values , level = None ):
2769
2762
"""
0 commit comments