Thanks to visit codestin.com
Credit goes to github.com

Skip to content

UnicodeDecodeError on Windows #10015

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
alimanfoo opened this issue Nov 13, 2017 · 2 comments
Closed

UnicodeDecodeError on Windows #10015

alimanfoo opened this issue Nov 13, 2017 · 2 comments

Comments

@alimanfoo
Copy link

I get the following behaviour on Windows only, using numpy 1.13.1 installed via conda:

>>> import numpy as np
>>> v = np.array('xxx', dtype='U3')[()]
>>> v
'xxx'
>>> a = np.empty(10, dtype='U3')
>>> a[:] = v
>>> a[0] == v
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-32-le' codec can't decode bytes in position 0-3: code point not in range(0x110000)

I don't understand what's happening here but this seemed surprising to me. Default locale on the Windows machine is cp1252 if that helps to know.

xref https://github.com/alimanfoo/zarr/pull/172

@eric-wieser
Copy link
Member

eric-wieser commented Nov 13, 2017

This is "that unicode scalar bug" again, and there's a dupe somewhere. More revealing:

>>> a = np.zeros(10, dtype='U3')
>>> a[:] = np.unicode_('xxx')
>>> a.view(np.void)
array([[120   0 120   0 120   0   0   0  64  47 105 -63],
       [120   0 120   0 120   0   0   0  64  47 105 -63],
       [120   0 120   0 120   0   0   0  64  47 105 -63],
       [120   0 120   0 120   0   0   0  64  47 105 -63],
       [120   0 120   0 120   0   0   0  64  47 105 -63],
       [120   0 120   0 120   0   0   0  64  47 105 -63],
       [120   0 120   0 120   0   0   0  64  47 105 -63],
       [120   0 120   0 120   0   0   0  64  47 105 -63],
       [120   0 120   0 120   0   0   0  64  47 105 -63],
       [120   0 120   0 120   0   0   0  64  47 105 -63]],
      dtype='|V12')

Notice that:

  • x is using up 2 bytes, not 4
  • The garbage at the end

Related to:

@eric-wieser
Copy link
Member

Found it.

Duplicate of #3258

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

2 participants