-
-
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
Fail to index table with iloc[] after dump/load table into pickle file #11332
Comments
Welcome to Astropy 👋 and thank you for your first issue! A project member will respond to you as soon as possible; in the meantime, please double-check the guidelines for submitting issues and make sure you've provided the requested details. If you feel that this issue has not been responded to in a timely manner, please leave a comment mentioning our software support engineer @embray, or send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail feedback@astropy.org. |
Thanks for reporting this. I also see the same behavior with 4.3.dev. Adding |
@jorgemarpa - with apologies, this is a known limitation of astropy Table indexing. The indexes are not saved in any of the supported formats such as pickle, FITS, HDF5, ECSV, etc. See #6925. In my test right now it is possible to regenerate the index after pickling with |
Huh... It didn't work for me but I can try again if you want. I did notice after I did that 3 times, I see multiple entries of the same stuff under But if it works for everyone else, then maybe it is just me. |
@pllim - I must have made a mistake in my test because I am reproducing the failure you reported. The oddity is that it only fails if Here is my minimum failing example:
|
@taldcroft , thanks for double-checking! Yes, that is consistent with the errors reported here. |
OK, just looked at the code. The indices which live on the columns are getting pickled, but the index object on the table is getting lost. This may be fixable... |
A workaround for now is to set the table
After doing this the |
Yes @taldcroft, I also found that after pickling the |
I know this issue is about pickles, but I wonder about other formats (HDF5, FITS). Should table reader/writer interfaces get (optional) methods for reading/writing indices. Perhaps there should also be a warning when dumping tables with indices if they cannot be saved. |
@embray - I've been thinking about this recently and it should not be too difficult, at least for the default The sorted containers tree is a bit less obvious for serialization and I'm not immediately sure how to handle that. |
Im not sure if this has something todo with it but this problem also happens when you create a new TimeSeries out of an old one like so |
EDIT: Temporary Workaround
See #11332 (comment)
Description
I am saving and loading a
Table
object into a pickle file, but after loading the table cannot be indexed using theiloc
method. I found that problem is because after loading the table doesn't the attributeTable.primary_key
Steps to Reproduce
leads to the following error:
and here when accessing the
primary_key
attribute of the original and post-pickle table:System Details
macOS-10.15.7-x86_64-i386-64bit
Python 3.8.6 (default, Jan 5 2021, 15:15:33)
[Clang 12.0.0 (clang-1200.0.32.28)]
Numpy 1.19.5
astropy 4.2
Scipy 1.6.0
Matplotlib 3.3.3
The text was updated successfully, but these errors were encountered: