8000 Opening Pickle Files using ma.dump in Python 3 · Issue #5491 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Opening Pickle Files using ma.dump in Python 3 #5491

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
JacksonTanBS opened this issue Jan 23, 2015 · 2 comments
Closed

Opening Pickle Files using ma.dump in Python 3 #5491

JacksonTanBS opened this issue Jan 23, 2015 · 2 comments

Comments

@JacksonTanBS
Copy link

When using numpy.ma.dump to save a masked array in Python 3:

np.ma.dump(a, pathtofile)

I got the following error:

/home/btan1/.virtualenvs/python3.3/lib/python3.3/site-packages/numpy/ma/core.py in dump(a, F)
   7141     if not hasattr(F, 'readline'):
   7142         F = open(F, 'w')
-> 7143     return pickle.dump(a, F)
   7144 
   7145 def dumps(a):

TypeError: must be str, not bytes

This is with NumPy 1.9.1 and Python 3.3.2.

From what I found out, it is because in Python 3 pickle files has to be opened in binary mode, i.e. L7142 should be F = open(F, 'wb'). Indeed, if I were to change it to:

with open(pathtofile, 'wb') as f:
    pickle.dump(a, f)

the error goes away.

@eric-wieser
Copy link
Member
eric-wieser commented Dec 10, 2017

Echoing my comments elsewhere:

Why on earth do any of these exist?

  • np.ma.dump
  • np.ma.load
  • np.ma.dumps
  • np.ma.loads

It seems pretty obvious to me that exposing a slightly-tweaked pickle api is not in scope for what ma should do, especially since these tweaks are broken on python 3 anyway (#5491).

Given that this is already broken on py3, I vote we leave it broken and simply add

warnings.warn(
    "np.ma.{method} is deprecated, use pickle.{method} instead".format(method=the_method_name),
    DeprecationWarning)

Which I've done in #10192

eric-wieser added a commit to eric-wieser/numpy that referenced this issue Dec 11, 2017
* The np.ma functions are misleading, as they do not actually do anything special for ma.array
* The np.loads functions doesn't even have numpy-specific documentation, and does not behave consistently with `np.load`
* The string overloads of np.ma.load and np.ma.dump do not work well on python 3, as they make assumptions about whether a binary or text pickle file is used (numpygh-5491)
@eric-wieser
Copy link
Member

Alright, closing as wont-fix - these functions will be deprecated in 1.15.0, as of #10192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0