11
11
12
12
import os
13
13
import numpy as np
14
+ import pathlib
14
15
15
16
from .filename_parser import splitext_addext
16
17
from .openers import ImageOpener
19
20
from .arrayproxy import is_proxy
20
21
from .deprecated import deprecate_with_version
21
22
23
+ def _stringify_path (filepath_or_buffer ):
24
+ """Attempt to convert a path-like object to a string.
25
+
26
+ Parameters
27
+ ----------
28
+ filepath_or_buffer : object to be converted
29
+ Returns
30
+ -------
31
+ str_filepath_or_buffer : maybe a string version of the object
32
+ Notes
33
+ -----
34
+ Objects supporting the fspath protocol (python 3.6+) are coerced
35
+ according to its __fspath__ method.
36
+ For backwards compatibility with older pythons, pathlib.Path and
37
+ py.path objects are specially coerced.
38
+ Any other object is passed through unchanged, which includes bytes,
39
+ strings, buffers, or anything else that's not even path-like.
40
+
41
+ Copied from:
42
+ https://github.com/pandas-dev/pandas/blob/325dd686de1589c17731cf93b649ed5ccb5a99b4/pandas/io/common.py#L131-L160
43
+ """
44
+ if hasattr (filepath_or_buffer , "__fspath__" ):
45
+ return filepath_or_buffer .__fspath__ ()
46
+ elif isinstance (filepath_or_buffer , pathlib .Path ):
47
+ return str (filepath_or_buffer )
48
+ return filepath_or_buffer
49
+
22
50
23
51
def load (filename , ** kwargs ):
24
52
''' Load file given filename, guessing at file type
@@ -35,11 +63,6 @@ def load(filename, **kwargs):
35
63
img : ``SpatialImage``
36
64
Image of guessed type
37
65
'''
38
- #Coerce pathlib objects
39
- if hasattr (filename , '__fspath__' ):
40
- filename = filename .__fspath__ ()
41
- else :
42
- filename = str (filename )
43
66
44
67
#Check file exists and is not empty
45
68
try :
0 commit comments