Skip to content

Commit ded19a2

Browse files
committed
add compatibility support for PEP 519 pandas-dev#13823
1 parent b895968 commit ded19a2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pandas/io/common.py

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
_PY_PATH_INSTALLED = False
4141

4242

43+
try:
44+
from os import fspath, PathLike
45+
_OS_FSPATH_INSTALLED = True
46+
except:
47+
_OS_FSPATH_INSTALLED = False
48+
49+
4350
if compat.PY3:
4451
from urllib.request import urlopen, pathname2url
4552
_urlopen = urlopen
@@ -183,6 +190,10 @@ def _stringify_path(filepath_or_buffer):
183190
-------
184191
str_filepath_or_buffer : a the string version of the input path
185192
"""
193+
if _OS_FSPATH_INSTALLED and isinstance(filepath_or_buffer, PathLike):
194+
return fspath(filepath_or_buffer)
195+
elif hasattr(filepath_or_buffer, "__fspath__"):
196+
return filepath_or_buffer.__fspath__()
186197
if _PATHLIB_INSTALLED and isinstance(filepath_or_buffer, pathlib.Path):
187198
return text_type(filepath_or_buffer)
188199
if _PY_PATH_INSTALLED and isinstance(filepath_or_buffer, LocalPath):

0 commit comments

Comments
 (0)