numpy.load() can't load matplotlib/sample_data/goog.npy in Python 3 #4798

Closed
frozflame opened this Issue Jun 10, 2014 · 2 comments

Comments

Projects
None yet
4 participants

A bug report. New to GitHub, I don't know it's proper to put this here this way.

See also in this stackoverflow post.

numpy.load() can't load matplotlib/sample_data/goog.npy in Python 3.4, but works in Python 2.7. NumPy version 1.8,1:

datafile = matplotlib.cbook.get_sample_data('goog.npy', asfileobj=False)
np.load(datafile)

and exception raised:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xd4 in position 1: ordinal not in range(128)

Someone on stackoverflow suggested to modify function read_array in numpy/lib/format.py from

array = pickle.load(fp)

to

array = pickle.load(fp, encoding = 'latin1')  #or
array = pickle.load(fp, encoding = 'bytes') 

but didn't work.

The .npy file can be found here. The full traceback I got:

UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-2-a5884b393c14> in <module>()
----> 1 np.load('Downloads/goog.npy')

/usr/lib/python3/dist-packages/numpy/lib/npyio.py in load(file, mmap_mode)
    392                 return format.open_memmap(file, mode=mmap_mode)
    393             else:
--> 394                 return format.read_array(fid)
    395         else:
    396             # Try a pickle

/usr/lib/python3/dist-packages/numpy/lib/format.py in read_array(fp)
    444     if dtype.hasobject:
    445         # The array contained Python objects. We need to unpickle the data.
--> 446         array = pickle.load(fp)
    447     else:
    448         if isfileobj(fp):

UnicodeDecodeError: 'ascii' codec can't decode byte 0xd4 in position 1: ordinal not in range(128)
Contributor

jakirkham commented Mar 2, 2016

So, maybe this should be closed. It appears that there is at least a way to do this. See code here. ( https://github.com/matplotlib/matplotlib/blob/ea11459f7a07666f434d659c6df2830a98305d70/examples/api/date_demo.py#L34 )

Owner

pv commented Mar 2, 2016

Yes, the present situation cannot be improved any more afaics.

pv closed this Mar 2, 2016

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