-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Retrieving rows in a table via a multi-column index fails (with possible fix) #13176
Comments
I am just a user of astropy and in need of the functionality described above (as a temporary solution I am relying on pandas MultiIndex). |
I had a quick look and I report that the error produced is different on astropy 6.0: Traceback (most recent call last):
File "/Users/clm/dev/astropy-project/astropy/bugs/13176/t.py", line 14, in <module>
t.loc[(1, 2)]
~~~~~^^^^^^^^
File "/Users/clm/dev/astropy-project/astropy/astropy/table/index.py", line 878, in __getitem__
rows = self._get_rows(item)
^^^^^^^^^^^^^^^^^^^^
File "/Users/clm/dev/astropy-project/astropy/astropy/table/index.py", line 843, in _get_rows
index = self.indices[key]
~~~~~~~~~~~~^^^^^
File "/Users/clm/dev/astropy-project/astropy/astropy/table/index.py", line 814, in __getitem__
return super().__getitem__(item)
^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: list index out of range I don't think the proposed patch is sufficient now, since the |
@taldcroft just to be sure, can I ask what behaviour you'd expect here ? |
The expected output would be below, i.e. the rows with
For reference here is the table in the original example:
|
@neutrinoceros - the table indexing code was written a while ago by a GSoC student. I've always found the code a bit difficult to understand... anyway this is a fine opportunity to dig into |
Yes, it may take me more time than I first thought but I'll give this a real try soon. Thank you very much for your replies ! |
Just a quick note for now; I think that I was misguided when I wrote #13176 (comment) : I don't think the I'll study the logic more deeply. |
Description
The current code for table indexing precludes using
.loc[item]
for a multi-column index whereitem
is a tuple. See this slack thread for more context.Expected behavior
It should just work.
Actual behavior
You get
ValueError("Cannot use .loc on multi-column indices")
.Steps to Reproduce
Possible solution
The solution below appears (at first glance) to allow using a multi-column index using
t.loc[keys, (1, 2)]
. I have not tried running tests with this.The text was updated successfully, but these errors were encountered: