Open bravegag opened 3 years ago
Thanks @bravegag for the report - to expedite resoultion, could you please make your example more minimal? Currently there are lots of columns which seem irrelevant, and the example is pretty long
@MarcoGorelli I have tried that to simplify the problem but then, I can no longer reproduce the issue. I have not been able to scale it down to a super simple example. It was already a lot of work to obfuscate the real data behind a,b,c.
In order to provide more context into this problem please check these two QAs. The first one is my original use-case, the second one is a description on this same problem after trying to implement the first OP.
This reproduces the error on master:
index = pd.MultiIndex.from_tuples(
[("a", "a1"), ("a", "a2"), ("a", "a3"), ("a", "a4"), ("a", "a5")]
)
my_dict = {
("a",): "x1",
("b",): "x1",
("c", "c1"): "x1",
("c", "c2"): "x1",
("c", "c3"): "x1",
}
pd.Index(index).map(my_dict)
---------------------------------------------------------------------------
InvalidIndexError Traceback (most recent call last)
<ipython-input-1-077a7247623d> in <module>
9 ("c", "c3"): "x1",
10 }
---> 11 pd.Index(index).map(my_dict)
~/pandas-marco/pandas/core/indexes/base.py in map(self, mapper, na_action)
5376 from pandas.core.indexes.multi import MultiIndex
5377
-> 5378 new_values = super()._map_values(mapper, na_action=na_action)
5379
5380 attributes = self._get_attributes_dict()
~/pandas-marco/pandas/core/base.py in _map_values(self, mapper, na_action)
928 values = self._values
929
--> 930 indexer = mapper.index.get_indexer(values)
931 new_values = algorithms.take_nd(mapper._values, indexer)
932
~/pandas-marco/pandas/core/indexes/base.py in get_indexer(self, target, method, limit, tolerance)
3379
3380 if not self._index_as_unique:
-> 3381 raise InvalidIndexError(self._requires_unique_msg)
3382
3383 if not self._should_compare(target) and not is_interval_dtype(self.dtype):
InvalidIndexError: Reindexing only valid with uniquely valued Index objects
@MarcoGorelli Any workaround for this issue under this bug get resolved, I am getting similar issues and i got blocked. It will be great if there is any work around on this issue
take
I am using Pandas 1.1.5 and get to the error
ValueError: Reindexing only valid with uniquely valued Index objects
.Here is a self contained MRE:
traceback: