Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

numpy.save rejects unicode paths in Python 2.7 #12749

Copy link
Copy link
Closed
@effigies

Description

@effigies
Issue body actions

We've discovered this in our tests in nipy/nipype when 1.16 was released (failing test). It's unclear why it wasn't hitting our --pre tests, but it wasn't too tough to track down and reproduce.

It appears to have been introduced in #12157, which dropped an if isinstance(file, basestring): and explicitly checks str and bytes, which will resolve to str and str in Python 2, not unicode and str.

This is probably easily fixable on our end (just call str()), but in case you intend to support unicode paths, you should know about this.

Related: nipy/nipype#2855

Reproducing code example:

from __future__ import unicode_literals
import numpy as np
np.save('abc.npy', np.array([0, 1, 2])

Error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-109f1bba4449> in <module>()
----> 1 np.save('abc.npy', np.array([0, 1, 2]))

/anaconda3/envs/python27/lib/python2.7/site-packages/numpy/lib/npyio.pyc in save(file, arr, allow_pickle, fix_imports)
    512         fid = file
    513     else:
--> 514         file = os_fspath(file)
    515         if not file.endswith('.npy'):
    516             file = file + '.npy'

/anaconda3/envs/python27/lib/python2.7/site-packages/numpy/compat/py3k.pyc in os_fspath(path)
    235             else:
    236                 raise TypeError("expected str, bytes or os.PathLike object, "
--> 237                                 "not " + path_type.__name__)
    238         if isinstance(path_repr, (str, bytes)):
    239             return path_repr

TypeError: expected str, bytes or os.PathLike object, not unicode

Numpy/Python version information:

('1.16.0', '2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 13:10:39) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.