Skip to content

Commit

Permalink
ENH simplify by removing conditional repack
Browse files Browse the repository at this point in the history
  • Loading branch information
kwgoodman committed Dec 20, 2013
1 parent 3bfc51f commit 857a7af
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions la/io.py
Expand Up @@ -56,13 +56,6 @@ def __init__(self, filename, max_freespace=np.inf):
filename : str
The `filename` is the path to the archive. If the file does not
exists, it will be created.
max_freespace : scalar
If the size of the freespace (unused archive space) exceeds
`max_freespace` bytes after a larry is deleted from the archive,
then the archive is repacked. The default (np.inf) is to never
repack. Repack means to transfer all the larrys to a new archive
(with the same name) and delete the old archive. HDF5 does not
reuse the freespace across openening and closing of the archive.
Returns
-------
Expand All @@ -81,8 +74,7 @@ def __init__(self, filename, max_freespace=np.inf):
- Deleting a larry from the archive only unlinks it. You won't be able
to reuse the unlinked space if you close the connection. This is
a limitation of the HDF5 format, not a limitation of the IO class
or h5py. You can repack the archive with the repack method or have
it done automatically for you: see `freespace` above.
or h5py. You can repack the archive with the repack method.
Examples
--------
Expand Down Expand Up @@ -162,7 +154,6 @@ def clear(self):
"""
for key in self:
self.__delitem__(key)
self._repack_conditional()

def merge(self, key, lar, update=False):
"""
Expand Down Expand Up @@ -225,7 +216,6 @@ def __setitem__(self, key, value):

def __delitem__(self, key):
delete(self.f, key)
self._repack_conditional()

def __repr__(self):
table = [['larry', 'dtype', 'shape']]
Expand Down Expand Up @@ -260,14 +250,15 @@ def sizefinder(key, value):
return self.space - size

def repack(self):
"Repack archive to remove freespace."
self.f = repack(self.f)
"""
Repack archive to remove freespace.
Repack means to transfer all the larrys to a new archive (with the
same name) and delete the old archive. HDF5 does not reuse the
freespace across openening and closing of the archive.
def _repack_conditional(self):
"Repack if `max_freespace` is exceeded."
if np.isfinite(self.max_freespace):
if self.freespace() > self.max_freespace:
self.f = self.repack()
"""
self.f = repack(self.f)

@property
def filename(self):
Expand Down

0 comments on commit 857a7af

Please sign in to comment.