From 7def892579f249e9f13a9237e8c76f6c55943c05 Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Sun, 19 May 2019 10:47:26 +0530 Subject: [PATCH 1/7] Added DeprecationWarning for py.path.local --- pandas/io/common.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/io/common.py b/pandas/io/common.py index f9cd1806763e2..8c543426c51fe 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -15,6 +15,7 @@ uses_relative) from urllib.request import pathname2url, urlopen import zipfile +import warnings from pandas.errors import ( # noqa AbstractMethodError, DtypeWarning, EmptyDataError, ParserError, @@ -124,6 +125,8 @@ def _stringify_path(filepath_or_buffer): try: from py.path import local as LocalPath _PY_PATH_INSTALLED = True + warnings.warn("py.path has been deprecated. Use pathlib instead.", + DeprecationWarning, stacklevel=2) except ImportError: _PY_PATH_INSTALLED = False From f462cc2fae2abb037cfb3a1b221029d243a25276 Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Sun, 19 May 2019 13:25:51 +0530 Subject: [PATCH 2/7] Raise warning only if py.path used --- pandas/io/common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/io/common.py b/pandas/io/common.py index 8c543426c51fe..a676b52761f14 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -123,10 +123,8 @@ def _stringify_path(filepath_or_buffer): _PATHLIB_INSTALLED = False try: - from py.path import local as LocalPath + from py.path import local as LocalPath # Deprecated - 0.25.0 _PY_PATH_INSTALLED = True - warnings.warn("py.path has been deprecated. Use pathlib instead.", - DeprecationWarning, stacklevel=2) except ImportError: _PY_PATH_INSTALLED = False @@ -135,6 +133,8 @@ def _stringify_path(filepath_or_buffer): if _PATHLIB_INSTALLED and isinstance(filepath_or_buffer, pathlib.Path): return str(filepath_or_buffer) if _PY_PATH_INSTALLED and isinstance(filepath_or_buffer, LocalPath): + warnings.warn("py.path has been deprecated. Use pathlib instead.", + DeprecationWarning, stacklevel=2) return filepath_or_buffer.strpath return _expand_user(filepath_or_buffer) From 30d643cdd3e4b6564634216311c9c53cb9546a6a Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Sun, 19 May 2019 14:11:41 +0530 Subject: [PATCH 3/7] Corrected import order --- pandas/io/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/common.py b/pandas/io/common.py index a676b52761f14..89f08628bf246 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -14,8 +14,8 @@ urlencode, urljoin, urlparse as parse_url, uses_netloc, uses_params, uses_relative) from urllib.request import pathname2url, urlopen -import zipfile import warnings +import zipfile from pandas.errors import ( # noqa AbstractMethodError, DtypeWarning, EmptyDataError, ParserError, From 6dffe48c788726604daf5e0e633f6595b9a07922 Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Sun, 19 May 2019 23:49:21 +0530 Subject: [PATCH 4/7] Removed unwanted imports and checks --- pandas/io/common.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/pandas/io/common.py b/pandas/io/common.py index 89f08628bf246..e65eeecf90fd8 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -14,7 +14,6 @@ urlencode, urljoin, urlparse as parse_url, uses_netloc, uses_params, uses_relative) from urllib.request import pathname2url, urlopen -import warnings import zipfile from pandas.errors import ( # noqa @@ -116,26 +115,8 @@ 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 # Deprecated - 0.25.0 - _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): return str(filepath_or_buffer) - if _PY_PATH_INSTALLED and isinstance(filepath_or_buffer, LocalPath): - warnings.warn("py.path has been deprecated. Use pathlib instead.", - DeprecationWarning, stacklevel=2) - return filepath_or_buffer.strpath return _expand_user(filepath_or_buffer) From 022cd16c1da8b19e61e37b483beb5890173f19a0 Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Mon, 20 May 2019 00:33:12 +0530 Subject: [PATCH 5/7] Used __fspath__() in return --- pandas/io/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/common.py b/pandas/io/common.py index e65eeecf90fd8..1ed4c1dbe4964 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -116,7 +116,7 @@ def _stringify_path(filepath_or_buffer): strings, buffers, or anything else that's not even path-like. """ if hasattr(filepath_or_buffer, '__fspath__'): - return str(filepath_or_buffer) + return filepath_or_buffer.__fspath__() return _expand_user(filepath_or_buffer) From cb78cb9074c9a0a7cca2c8aab2e7f66315a49967 Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Mon, 20 May 2019 10:35:52 +0530 Subject: [PATCH 6/7] Changes for 3.5 --- pandas/io/common.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/io/common.py b/pandas/io/common.py index 1ed4c1dbe4964..5941a9efb92f5 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -115,8 +115,11 @@ 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. """ + import pathlib if hasattr(filepath_or_buffer, '__fspath__'): return filepath_or_buffer.__fspath__() + elif isinstance(filepath_or_buffer, pathlib.Path): + return str(filepath_or_buffer) return _expand_user(filepath_or_buffer) From 45f05784ac2a10c700c033c3c982598f49d9501c Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Sat, 25 May 2019 11:24:27 +0530 Subject: [PATCH 7/7] Move import --- pandas/io/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/common.py b/pandas/io/common.py index 5941a9efb92f5..34635ebf64ad6 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -9,6 +9,7 @@ import lzma import mmap import os +import pathlib from urllib.error import URLError # noqa from urllib.parse import ( # noqa urlencode, urljoin, urlparse as parse_url, uses_netloc, uses_params, @@ -115,7 +116,6 @@ 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. """ - import pathlib if hasattr(filepath_or_buffer, '__fspath__'): return filepath_or_buffer.__fspath__() elif isinstance(filepath_or_buffer, pathlib.Path):