-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
read_pickle error for multi-index: 'FrozenList' does not support mutable operations. #4788
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
Comments
try with current master; this fixed the pickle issue: 725b195 |
you can save mi for both index/colmns via csv since 0.12, see here: http://pandas.pydata.org/pandas-docs/dev/io.html#reading-columns-with-a-multiindex here for just mi on the index (ths has been for a while): http://pandas.pydata.org/pandas-docs/dev/io.html#reading-an-index-with-a-multiindex |
|
That said, I would not be surprised if the new |
@jtratner should be from 0.10 on....I saved a pickled version from each (and 0.13).... @d10genes do you see that commit I referenced (just @d10genes that error is a fall thru; I think there is another error can you debug thru pdb and step thru the basically it tries the original pickle, then the fallback, then a version with an encoding, then fallback with encoding are you using 2.7? (or a 3x) python? |
@d10genes can you post a sample code? |
@jreback This shows up in
|
As far as sample code, how do you want it different from the OP? |
@d10genes sorry...you put it up already....hold on |
I have a test for a mi and a frame with several kinds of index...but of course not a mi....let me fix. thanks for the report! (some of this pickle code was pretty tricky and was trying to cover all the bases!) |
Ok, thanks. And out of curiosity, would the underlying code for pickling treat Series and DataFrames differently? Going off of my above code, it looks like series MI pickling sets off that other error:
|
no...the problem is assigning the index to the pandas object, same code for all (but the deserialization of the MI is not 'defined' correctly) |
@jreback if you want me to look at it, I can... I have a hunch. (but you |
i have the test case set and will look in a few |
ok..this branch, last commti shows the test case: https://github.com/jreback/pandas/tree/pickle_fix a bunch of things are commented out...but this will fail on a disabled method in FrozenList pickle is trying to extend the list.... a possible solution is to have a context manager with certain classes (or can just do it with a try:except:finally (e.g. FrozenList), which reenables all/certain methods and then redisables them..... |
@jreback yeah, I was noticing that... would it work to just define def __reduce__(self):
return self.__class__, (list(self),) |
btw - how come |
@jreback yep, that resolves it - much simpler. |
only issue is whether we have to support legacy pickles from the time between the |
@jreback I can step through tomorrow morning if it'd still be helpful. And I'm using 2.7 |
@d10genes thanks that said glad you caught this was able to put some additional tests in place to ensure compat (which actually is a big deal as 0.13 changes a lot internally), including some hoops that needed jumping for Series (which is not not a subclass of ndarray) in any event will be merging soon (prob tomorrow) so keep a look out, @jtratner is fixing a couple of more things also pls try out the csv features I mentioned above if u can |
@d10genes all merged in, master should work for you now...thanks! |
Awesome, that fixed it. Thanks a lot, I really appreciate it. And regarding the csv features, I did try them out and they seemed to work, but I don't think it's possible with CSV to automatically encode which columns are indices (looks like pandas needs you to use the column names as Pickling seems to take care of it all though. Thanks! |
@d10genes great....yep...have to specify column names, unfortunately csv is not a roundtripable format (w/o some user parameters). |
I'm in a bit of a pickle here. If I try to save and read back a multi-indexed dataframe, I get this error (and in some situations, can't reproduce when, I get a
TypeError: Required argument 'shape' (pos 1) not found
error).The gist with the full traceback is here.
When I
reset_index
it saves fine. I'm on Mac OSX, numpy 1.7, pandas 0.12.0-361-g53eec08.In the meantime, if there's no quick fix, anyone know another way to save multi-indexes to file? csv doesn't look like it can preserve them. I could do something like appending
_index
to the columns and un-rename them after reading but would prefer something less hacky.The text was updated successfully, but these errors were encountered: