Skip to content

Commit c435e72

Browse files
committed
Merge pull request #5425 from jreback/temp_file
TST: Use tempfiles in all tests.
2 parents caf3d66 + 9058d50 commit c435e72

File tree

6 files changed

+233
-236
lines changed

6 files changed

+233
-236
lines changed

doc/source/release.rst

+1
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

+16-8
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
"""
@@ -389,6 +384,10 @@ def root(self):
389384
self._check_if_open()
390385
return self._handle.root
391386

387+
@property
388+
def filename(self):
389+
return self._path
390+
392391
def __getitem__(self, key):
393392
return self.get(key)
394393

@@ -475,6 +474,8 @@ def open(self, mode='a'):
475474
mode : {'a', 'w', 'r', 'r+'}, default 'a'
476475
See HDFStore docstring or tables.openFile for info about modes
477476
"""
477+
tables = _tables()
478+
478479
if self._mode != mode:
479480

480481
# if we are chaning a write mode to read, ok
@@ -501,13 +502,20 @@ def open(self, mode='a'):
501502
fletcher32=self._fletcher32)
502503

503504
try:
504-
self._handle = h5_open(self._path, self._mode)
505-
except IOError as e: # pragma: no cover
505+
self._handle = tables.openFile(self._path, self._mode)
506+
except (IOError) as e: # pragma: no cover
506507
if 'can not be written' in str(e):
507508
print('Opening %s in read-only mode' % self._path)
508-
self._handle = h5_open(self._path, 'r')
509+
self._handle = tables.openFile(self._path, 'r')
509510
else:
510511
raise
512+
except (Exception) as e:
513+
514+
# trying to read from a non-existant file causes an error which
515+
# is not part of IOError, make it one
516+
if self._mode == 'r' and 'Unable to open/create file' in str(e):
517+
raise IOError(str(e))
518+
raise
511519

512520
def close(self):
513521
"""

0 commit comments

Comments
 (0)