From 2b422d2af18926e2a043bebef6f77db943a85112 Mon Sep 17 00:00:00 2001 From: jreback Date: Thu, 9 Jan 2014 11:38:11 -0500 Subject: [PATCH] TST: Testing bug in reading json/msgpack from a non-filepath on windows under py3 (GH5874) --- doc/source/release.rst | 1 + pandas/io/json.py | 10 +++++++++- pandas/io/packers.py | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index d8e06c1ce9169..071b6e77fc2eb 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -83,6 +83,7 @@ Bug Fixes - Bug in groupby dtype conversion with datetimelike (:issue:`5869`) - Regresssion in handling of empty Series as indexers to Series (:issue:`5877`) - Bug in internal caching, related to (:issue:`5727`) + - Testing bug in reading json/msgpack from a non-filepath on windows under py3 (:issue:`5874`) pandas 0.13.0 ------------- diff --git a/pandas/io/json.py b/pandas/io/json.py index 83c503e7419e9..698f7777a1100 100644 --- a/pandas/io/json.py +++ b/pandas/io/json.py @@ -173,7 +173,15 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True, filepath_or_buffer, _ = get_filepath_or_buffer(path_or_buf) if isinstance(filepath_or_buffer, compat.string_types): - if os.path.exists(filepath_or_buffer): + try: + exists = os.path.exists(filepath_or_buffer) + + # if the filepath is too long will raise here + # 5874 + except (TypeError,ValueError): + exists = False + + if exists: with open(filepath_or_buffer, 'r') as fh: json = fh.read() else: diff --git a/pandas/io/packers.py b/pandas/io/packers.py index 5d392e94106e9..eba2579e80ea8 100644 --- a/pandas/io/packers.py +++ b/pandas/io/packers.py @@ -147,11 +147,11 @@ def read(fh): if isinstance(path_or_buf, compat.string_types): try: - path_exists = os.path.exists(path_or_buf) - except (TypeError): - path_exists = False + exists = os.path.exists(path_or_buf) + except (TypeError,ValueError): + exists = False - if path_exists: + if exists: with open(path_or_buf, 'rb') as fh: return read(fh)