Skip to content

Pickle not working #27029

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

Closed
dqii opened this issue Jun 25, 2019 · 4 comments
Closed

Pickle not working #27029

dqii opened this issue Jun 25, 2019 · 4 comments

Comments

@dqii
Copy link

dqii commented Jun 25, 2019

I'm trying to pickle a dataframe with to_pickle and read_pickle, and when reading I get this error

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~/miniconda3/lib/python3.7/site-packages/pandas/io/pickle.py in try_read(path, encoding)
165 warnings.simplefilter("ignore", Warning)
--> 166 return read_wrapper(lambda f: pkl.load(f))
167 except Exception: # noqa: E722

~/miniconda3/lib/python3.7/site-packages/pandas/io/pickle.py in read_wrapper(func)
145 compression=compression,
--> 146 is_text=False)
147 try:

~/miniconda3/lib/python3.7/site-packages/pandas/io/common.py in _get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text)
412 msg = 'Unrecognized compression type: {}'.format(compression)
--> 413 raise ValueError(msg)
414

ValueError: Unrecognized compression type: infer

When adding "compression=None" as an argument to both to_pickle and read_pickle, I get this error instead

TypeError Traceback (most recent call last)
~/miniconda3/lib/python3.7/site-packages/pandas/io/pickle.py in try_read(path, encoding)
165 warnings.simplefilter("ignore", Warning)
--> 166 return read_wrapper(lambda f: pkl.load(f))
167 except Exception: # noqa: E722

~/miniconda3/lib/python3.7/site-packages/pandas/io/pickle.py in read_wrapper(func)
147 try:
--> 148 return func(f)
149 finally:

~/miniconda3/lib/python3.7/site-packages/pandas/io/pickle.py in (f)
165 warnings.simplefilter("ignore", Warning)
--> 166 return read_wrapper(lambda f: pkl.load(f))
167 except Exception: # noqa: E722

TypeError: file must have 'read' and 'readline' attributes

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
~/miniconda3/lib/python3.7/site-packages/pandas/io/pickle.py in try_read(path, encoding)
172 return read_wrapper(
--> 173 lambda f: pc.load(f, encoding=encoding, compat=False))
174 # compat pickle

~/miniconda3/lib/python3.7/site-packages/pandas/io/pickle.py in read_wrapper(func)
147 try:
--> 148 return func(f)
149 finally:

~/miniconda3/lib/python3.7/site-packages/pandas/io/pickle.py in (f)
172 return read_wrapper(
--> 173 lambda f: pc.load(f, encoding=encoding, compat=False))
174 # compat pickle

~/miniconda3/lib/python3.7/site-packages/pandas/compat/pickle_compat.py in load(fh, encoding, compat, is_verbose)
219 try:
--> 220 fh.seek(0)
221 if encoding is not None:

~/miniconda3/lib/python3.7/site-packages/pandas/core/generic.py in getattr(self, name)
5066 return self[name]
-> 5067 return object.getattribute(self, name)
5068

AttributeError: 'DataFrame' object has no attribute 'seek'

Is this a bug?

@akhmerov
Copy link

Did you try finding a minimal reproducible example? AttributeError: 'DataFrame' object has no attribute 'seek' suggests that the bug is in your code.

@jorisvandenbossche
Copy link
Member

That's in any case not the expected behaviour. Can you try to make a reproducible example? Where and how are you saving the pickle file? (passing a file path?)

@jorisvandenbossche jorisvandenbossche added the Needs Info Clarification about behavior needed to assess issue label Jun 25, 2019
@dqii
Copy link
Author

dqii commented Jun 25, 2019

After trying to replicate the error and failing, I realized that the error was that I was calling read_pickle with a dataframe as opposed to the file name, as you are supposed to do. I'm sorry about this.

In hindsight, the error AttributeError: 'DataFrame' object has no attribute 'seek' was a clear indication of this error. For the future, is it possible the first error message could be any clearer? Either way I should have realized this earlier.

Thank you both for having taken a look.

@jorisvandenbossche
Copy link
Member

OK, no problem. Closing then.

@jorisvandenbossche jorisvandenbossche removed the Needs Info Clarification about behavior needed to assess issue label Jun 26, 2019
@jorisvandenbossche jorisvandenbossche added this to the No action milestone Jun 26, 2019
@jreback jreback closed this as completed Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants