Skip to content

Commit 08c5b8a

Browse files
committed
PERF: delay import of py.path, Pathlib
1 parent ef0c60d commit 08c5b8a

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

pandas/io/common.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,6 @@
2727
'N/A', 'n/a', 'NA', '#NA', 'NULL', 'null', 'NaN', '-NaN', 'nan', '-nan', ''
2828
])
2929

30-
try:
31-
import pathlib
32-
_PATHLIB_INSTALLED = True
33-
except ImportError:
34-
_PATHLIB_INSTALLED = False
35-
36-
37-
try:
38-
from py.path import local as LocalPath
39-
_PY_PATH_INSTALLED = True
40-
except:
41-
_PY_PATH_INSTALLED = False
42-
4330

4431
if compat.PY3:
4532
from urllib.request import urlopen, pathname2url
@@ -160,6 +147,18 @@ def _stringify_path(filepath_or_buffer):
160147
Any other object is passed through unchanged, which includes bytes,
161148
strings, buffers, or anything else that's not even path-like.
162149
"""
150+
try:
151+
import pathlib
152+
_PATHLIB_INSTALLED = True
153+
except ImportError:
154+
_PATHLIB_INSTALLED = False
155+
156+
try:
157+
from py.path import local as LocalPath
158+
_PY_PATH_INSTALLED = True
159+
except ImportError:
160+
_PY_PATH_INSTALLED = False
161+
163162
if hasattr(filepath_or_buffer, '__fspath__'):
164163
return filepath_or_buffer.__fspath__()
165164
if _PATHLIB_INSTALLED and isinstance(filepath_or_buffer, pathlib.Path):

0 commit comments

Comments
 (0)