Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
indexing.py: "'bool' object has no attribtute 'any'" with duplicate time index #17105
Code Sample, a copy-pastable example if possible
trange = pd.date_range(start=pd.Timestamp(year=2017, month=1, day=1), end=pd.Timestamp(year=2017, month=1, day=5)) # make a duplicate trange = trange.insert(loc=5, item=pd.Timestamp(year=2017, month=1, day=5)) df = pd.DataFrame(0, index=trange, columns=["A", "B"]) bool_idx = np.array([True, False, False, False, False, True]) df.loc[trange[bool_idx], "A"] += 1
First I wasn't aware that I have a duplicated index in my code -- I only realised this when trying to reproduce the error in the example above. I used time index, because in my code I have a time index too.
The problem is in indexing.py line 1235 and 1236, where the variable
I am not sure if the code is legal with duplicates (I will filter duplicates in my code now). Nonetheless, I think a decent error message should be raised in such a case.
We generally would discourage against having duplicates, regardless if in the
I don't think there is a reason that this shouldn't work. Duplicate indices for certain operations are not supported (eg reindexing) and are often not advisable, but for basic indexing certainly supported.
so only when setting the value it fails.
Further, the equivalent example using an integer index also seems to work correctly: