Skip to content

Commit

Permalink
TST: Use tempfiles in all tests.
Browse files Browse the repository at this point in the history
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

TST: fix temporary files by using mktemp (rather than mkstemp) which opens them
  • Loading branch information
jtratner authored and jreback committed Nov 3, 2013
1 parent 8828dbf commit d07ae98
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 113 deletions.
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ Bug Fixes
- The GroupBy methods ``transform`` and ``filter`` can be used on Series
and DataFrames that have repeated (non-unique) indices. (:issue:`4620`)
- Fix empty series not printing name in repr (:issue:`4651`)
- Make tests create temp files in temp directory by default. (:issue:`5419`)

pandas 0.12.0
-------------
Expand Down
24 changes: 16 additions & 8 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,6 @@ def _tables():
return _table_mod


def h5_open(path, mode):
tables = _tables()
return tables.openFile(path, mode)


@contextmanager
def get_store(path, **kwargs):
"""
Expand Down Expand Up @@ -389,6 +384,10 @@ def root(self):
self._check_if_open()
return self._handle.root

@property
def filename(self):
return self._path

def __getitem__(self, key):
return self.get(key)

Expand Down Expand Up @@ -475,6 +474,8 @@ def open(self, mode='a'):
mode : {'a', 'w', 'r', 'r+'}, default 'a'
See HDFStore docstring or tables.openFile for info about modes
"""
tables = _tables()

if self._mode != mode:

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

try:
self._handle = h5_open(self._path, self._mode)
except IOError as e: # pragma: no cover
self._handle = tables.openFile(self._path, self._mode)
except (IOError) as e: # pragma: no cover
if 'can not be written' in str(e):
print('Opening %s in read-only mode' % self._path)
self._handle = h5_open(self._path, 'r')
self._handle = tables.openFile(self._path, 'r')
else:
raise
except (Exception) as e:

# trying to read from a non-existant file causes an error which
# is not part of IOError, make it one
if self._mode == 'r' and 'Unable to open/create file' in str(e):
raise IOError(str(e))
raise

def close(self):
"""
Expand Down
Loading

0 comments on commit d07ae98

Please sign in to comment.