|
11 | 11 |
|
12 | 12 | import os
|
13 | 13 | import numpy as np
|
14 |
| -import pathlib |
15 | 14 |
|
16 |
| -from .filename_parser import splitext_addext |
| 15 | +from .filename_parser import splitext_addext, _stringify_path |
17 | 16 | from .openers import ImageOpener
|
18 | 17 | from .filebasedimages import ImageFileError
|
19 | 18 | from .imageclasses import all_image_classes
|
20 | 19 | from .arrayproxy import is_proxy
|
21 | 20 | from .deprecated import deprecate_with_version
|
22 | 21 |
|
23 |
| -def _stringify_path(filepath_or_buffer): |
24 |
| - """Attempt to convert a path-like object to a string. |
25 | 22 |
|
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 | 23 |
|
50 | 24 |
|
51 | 25 | def load(filename, **kwargs):
|
|
0 commit comments