Skip to content

Commit

Permalink
PERF: delay import of py.path, Pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Sep 28, 2017
1 parent ef0c60d commit 08c5b8a
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@
'N/A', 'n/a', 'NA', '#NA', 'NULL', 'null', 'NaN', '-NaN', 'nan', '-nan', ''
])

try:
import pathlib
_PATHLIB_INSTALLED = True
except ImportError:
_PATHLIB_INSTALLED = False


try:
from py.path import local as LocalPath
_PY_PATH_INSTALLED = True
except:
_PY_PATH_INSTALLED = False


if compat.PY3:
from urllib.request import urlopen, pathname2url
Expand Down Expand Up @@ -160,6 +147,18 @@ def _stringify_path(filepath_or_buffer):
Any other object is passed through unchanged, which includes bytes,
strings, buffers, or anything else that's not even path-like.
"""
try:
import pathlib
_PATHLIB_INSTALLED = True
except ImportError:
_PATHLIB_INSTALLED = False

try:
from py.path import local as LocalPath
_PY_PATH_INSTALLED = True
except ImportError:
_PY_PATH_INSTALLED = False

if hasattr(filepath_or_buffer, '__fspath__'):
return filepath_or_buffer.__fspath__()
if _PATHLIB_INSTALLED and isinstance(filepath_or_buffer, pathlib.Path):
Expand Down

0 comments on commit 08c5b8a

Please sign in to comment.