Skip to content

Commit 6946224

Browse files
committed
add compatibility support for PEP 519 #13823
1 parent cc216ad commit 6946224

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
@@ -28,6 +28,13 @@
2828
_PY_PATH_INSTALLED = False
2929

3030

31+
try:
32+
from os import fspath, PathLike
33+
_OS_FSPATH_INSTALLED = True
34+
except:
35+
_OS_FSPATH_INSTALLED = False
36+
37+
3138
if compat.PY3:
3239
from urllib.request import urlopen, pathname2url
3340
_urlopen = urlopen
@@ -202,6 +209,10 @@ def _stringify_path(filepath_or_buffer):
202209
-------
203210
str_filepath_or_buffer : a the string version of the input path
204211
"""
212+
if _OS_FSPATH_INSTALLED and isinstance(filepath_or_buffer, PathLike):
213+
return fspath(filepath_or_buffer)
214+
elif hasattr(filepath_or_buffer, "__fspath__"):
215+
return filepath_or_buffer.__fspath__()
205216
if _PATHLIB_INSTALLED and isinstance(filepath_or_buffer, pathlib.Path):
206217
return text_type(filepath_or_buffer)
207218
if _PY_PATH_INSTALLED and isinstance(filepath_or_buffer, LocalPath):

0 commit comments

Comments
 (0)