Skip to content

Commit 7c7b7e0

Browse files
author
Sam Spilsbury
committed
io/packers: Just let python raise itself if the file was not found
As opposed to checking if it exists first.
1 parent ad2e98c commit 7c7b7e0

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

pandas/io/packers.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,8 @@ def read(fh):
176176

177177
# see if we have an actual file
178178
if isinstance(path_or_buf, str):
179-
try:
180-
exists = os.path.exists(path_or_buf)
181-
except (TypeError, ValueError):
182-
exists = False
183-
184-
if exists:
185-
with open(path_or_buf, 'rb') as fh:
186-
return read(fh)
179+
with open(path_or_buf, 'rb') as fh:
180+
return read(fh)
187181

188182
if isinstance(path_or_buf, bytes):
189183
# treat as a binary-like

pandas/tests/io/test_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_iterator(self):
140140
(pd.read_stata, 'os', FileNotFoundError, 'dta'),
141141
(pd.read_sas, 'os', FileNotFoundError, 'sas7bdat'),
142142
(pd.read_json, 'os', ValueError, 'json'),
143-
(pd.read_msgpack, 'os', ValueError, 'mp'),
143+
(pd.read_msgpack, 'os', FileNotFoundError, 'mp'),
144144
(pd.read_pickle, 'os', FileNotFoundError, 'pickle'),
145145
])
146146
def test_read_non_existant(self, reader, module, error_class, fn_ext):
@@ -169,7 +169,7 @@ def test_read_non_existant(self, reader, module, error_class, fn_ext):
169169
(pd.read_stata, 'os', FileNotFoundError, 'dta'),
170170
(pd.read_sas, 'os', FileNotFoundError, 'sas7bdat'),
171171
(pd.read_json, 'os', ValueError, 'json'),
172-
(pd.read_msgpack, 'os', ValueError, 'mp'),
172+
(pd.read_msgpack, 'os', FileNotFoundError, 'mp'),
173173
(pd.read_pickle, 'os', FileNotFoundError, 'pickle'),
174174
])
175175
def test_read_expands_user_home_dir(self, reader, module,

0 commit comments

Comments
 (0)