-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntervalIndex level in MultiIndex does not work as expected #25298
Comments
This is a bug. To my knowledge there hasn't been any work done to ensure that It does appear to be working in certain cases though, so there's at least some In [2]: mi = pd.MultiIndex.from_product([list('ab'), pd.interval_range(0, 2)])
In [3]: df = pd.DataFrame({'A': list('wxyz'), 'B': range(4)}, index=mi)
In [4]: df
Out[4]:
A B
a (0, 1] w 0
(1, 2] x 1
b (0, 1] y 2
(1, 2] z 3
In [5]: df.loc[('a', 1.1)]
Out[5]:
A x
B 1
Name: (a, (1, 2]), dtype: object
In [6]: df.loc[('a', 2)]
Out[6]:
A x
B 1
Name: (a, (1, 2]), dtype: object Investigation into the issue and PRs would certainly be welcome! |
Hi all, was this issue ever resolved? I have run into the same problem but a different error is thrown. If this has not been resolved I will raise this as an issue with some example code |
There are still issues with this ( Here I have made 2 similar DataFrames, but they behave differently: ii = pd.IntervalIndex.from_arrays(
[141104, 151056, 154080, 0],
[146512, 154832, 160000, 160000],
)
mi = pd.MultiIndex.from_arrays([["a", "a", "a", "b"], ii])
data = [[1], [2], [3], [4]]
df = pd.DataFrame(data, columns=["col"], index=mi)
print(df)
df.loc[("a", 152000)]
Changing the first interval to ii2 = pd.IntervalIndex.from_arrays(
[0, 151056, 154080, 0],
[160000, 154832, 160000, 160000],
)
mi2 = pd.MultiIndex.from_arrays([["a", "a", "a", "b"], ii2])
df2 = pd.DataFrame(data, columns=["col"], index=mi2)
df2.loc[("a", 152000)]
Somehow this query now works... On my real data, I have a query like the latter one (but only supposed to return one value) which gives a KeyError.
|
This works as expected now
|
take |
I am trying to index data frame with a
MultiIndex
with constituentIntervalIndex
Example
Above code throws
TypeError
as follows:I was expecting above to produce same result as:
Is this a bug or I'm not using it properly? (newbie here)
Version Details:
The text was updated successfully, but these errors were encountered: