Skip to content

Commit

Permalink
Merge tag 'v0.20.2'
Browse files Browse the repository at this point in the history
v0.20.2
  • Loading branch information
alimanfoo committed Dec 10, 2015
2 parents 1c187f4 + d007ba4 commit 65306d3
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 123 deletions.
2 changes: 1 addition & 1 deletion allel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
except ImportError:
pass

__version__ = '0.20.1'
__version__ = '0.20.2'
40 changes: 32 additions & 8 deletions allel/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, division


from contextlib import contextmanager
from functools import update_wrapper
import atexit
Expand All @@ -12,6 +10,9 @@
from scipy.spatial.distance import squareform


from allel.compat import string_types


@contextmanager
def ignore_invalid():
err = np.seterr(invalid='ignore')
Expand Down Expand Up @@ -187,7 +188,7 @@ def _hdf5_cache_act(filepath, parent, container, key, names, no_cache,
# determine dataset name
if names is None:
n = 'data'
elif isinstance(names, str):
elif isinstance(names, string_types):
n = names
elif len(names) > 0:
n = names[0]
Expand All @@ -209,7 +210,13 @@ def _hdf5_cache_act(filepath, parent, container, key, names, no_cache,
# load from cache
else:

names = sorted(h5g.keys())
# determine dataset names
if names is None:
names = sorted(h5g.keys())
elif isinstance(names, string_types):
names = (names,)

# load result from cache
if len(names) == 1:
result = h5g[names[0]]
result = result[:] if len(result.shape) > 0 else result[()]
Expand All @@ -222,7 +229,7 @@ def _hdf5_cache_act(filepath, parent, container, key, names, no_cache,


def hdf5_cache(filepath=None, parent=None, group=None, names=None, typed=False,
hashed_key=True, **h5dcreate_kwargs):
hashed_key=False, **h5dcreate_kwargs):
"""HDF5 cache decorator.
Parameters
Expand All @@ -244,8 +251,11 @@ def hdf5_cache(filepath=None, parent=None, group=None, names=None, typed=False,
For example, f(3.0) and f(3) will be treated as distinct calls with
distinct results.
hashed_key : bool, optional
If False, the key will not be hashed, which makes for readable cache
group names, but may cause problems if key contains '/' characters.
If False (default) the key will not be hashed, which makes for
readable cache group names. If True the key will be hashed, however
note that on Python >= 3.3 the hash value will not be the same between
sessions unless the environment variable PYTHONHASHSEED has been set
to the same value.
Returns
-------
Expand Down Expand Up @@ -284,6 +294,20 @@ def hdf5_cache(filepath=None, parent=None, group=None, names=None, typed=False,
>>> bar(3)
(array([0, 1, 2]), array([0, 1, 4]), 9)
Names can also be specified for the datasets, e.g.::
>>> @allel.util.hdf5_cache(names=['z', 'x', 'y'])
... def baz(n):
... print('executing baz')
... a = np.arange(n)
... return a, a**2, n**2
...
>>> baz(3)
executing baz
(array([0, 1, 2]), array([0, 1, 4]), 9)
>>> baz(3)
(array([0, 1, 2]), array([0, 1, 4]), 9)
"""

# initialise HDF5 file path
Expand Down Expand Up @@ -313,7 +337,7 @@ def wrapper(*args, **kwargs):
if hashed_key:
key = str(hash(key))
else:
key = str(key)
key = str(key).replace('/', '__slash__')

return _hdf5_cache_act(filepath, parent, container, key, names,
no_cache, user_function, args, kwargs,
Expand Down
8 changes: 8 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Release notes
=============

v0.20.2
-------

* Changed :func:`allel.util.hdf5_cache` to resolve issues with hashing and
argument order
(`#51 <https://github.com/cggh/scikit-allel/issues/51>`_,
`#52 <https://github.com/cggh/scikit-allel/issues/52>`_).

v0.20.1
-------

Expand Down

0 comments on commit 65306d3

Please sign in to comment.