Skip to content

Commit d26fb76

Browse files
committed
TST: Use tempfiles in all tests.
Includes @jreback's commits from pandas-dev#5422 and hdf_temp: * TST: make pytables tests go thru a temporary dir and file * TST/BUG: incorrect way of testing for r+ modes
1 parent 8828dbf commit d26fb76

File tree

6 files changed

+88
-113
lines changed

6 files changed

+88
-113
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ Bug Fixes
769769
- The GroupBy methods ``transform`` and ``filter`` can be used on Series
770770
and DataFrames that have repeated (non-unique) indices. (:issue:`4620`)
771771
- Fix empty series not printing name in repr (:issue:`4651`)
772+
- Make tests create temp files in temp directory by default. (:issue:`5419`)
772773

773774
pandas 0.12.0
774775
-------------

pandas/io/pytables.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,6 @@ def _tables():
225225
return _table_mod
226226

227227

228-
def h5_open(path, mode):
229-
tables = _tables()
230-
return tables.openFile(path, mode)
231-
232-
233228
@contextmanager
234229
def get_store(path, **kwargs):
235230
"""
@@ -475,6 +470,8 @@ def open(self, mode='a'):
475470
mode : {'a', 'w', 'r', 'r+'}, default 'a'
476471
See HDFStore docstring or tables.openFile for info about modes
477472
"""
473+
tables = _tables()
474+
478475
if self._mode != mode:
479476

480477
# if we are chaning a write mode to read, ok
@@ -501,13 +498,20 @@ def open(self, mode='a'):
501498
fletcher32=self._fletcher32)
502499

503500
try:
504-
self._handle = h5_open(self._path, self._mode)
505-
except IOError as e: # pragma: no cover
501+
self._handle = tables.openFile(self._path, self._mode)
502+
except (IOError) as e: # pragma: no cover
506503
if 'can not be written' in str(e):
507504
print('Opening %s in read-only mode' % self._path)
508-
self._handle = h5_open(self._path, 'r')
505+
self._handle = tables.openFile(self._path, 'r')
509506
else:
510507
raise
508+
except (Exception) as e:
509+
510+
# trying to read from a non-existant file causes an error which
511+
# is not part of IOError, make it one
512+
if self._mode == 'r' and 'Unable to open/create file' in str(e):
513+
raise IOError(str(e))
514+
raise
511515

512516
def close(self):
513517
"""

0 commit comments

Comments
 (0)