Skip to content

Commit 44e4a84

Browse files
committed
Fix bug related to converting a dictionary to a MultiIndex instead of an Index
1 parent 699055e commit 44e4a84

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

pandas/core/base.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -919,22 +919,15 @@ def map_f(values, f):
919919
arg = lambda x: dict_with_default[x]
920920
else:
921921
# Dictionary does not have a default. Thus it's safe to
922-
# convert to an Index for efficiency.
923-
from pandas import Index
924-
idx = Index(arg.keys())
925-
# Cast to dict so we can get values using lib.fast_multiget
926-
# if this is a dict subclass (GH #15999)
927-
map_values = idx._get_values_from_dict(dict(arg))
928-
arg = idx
929-
elif isinstance(arg, ABCSeries):
930-
map_values = arg.values
931-
arg = arg.index
932-
933-
if map_values is not None:
922+
# convert to an Series for efficiency.
923+
from pandas import Series
924+
arg = Series(arg, index=arg.keys())
925+
926+
if isinstance(arg, ABCSeries):
934927
# Since values were input this means we came from either
935928
# a dict or a series and arg should be an index
936-
indexer = arg.get_indexer(values)
937-
new_values = algorithms.take_1d(map_values, indexer)
929+
indexer = arg.index.get_indexer(values)
930+
new_values = algorithms.take_1d(arg._values, indexer)
938931
else:
939932
# arg is a function
940933
new_values = map_f(values, arg)

0 commit comments

Comments
 (0)