Skip to content

Commit

Permalink
FIX: More conservative default for object_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Jun 16, 2014
1 parent e01741f commit c4f715a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ def __next__(self, *args, **kwargs):
def __hash__(self):
if not self.preload:
raise RuntimeError('Cannot hash epochs unless preloaded')
return object_hash(dict(info=self.info, data=self._data))
return object_hash(dict(info=self.info, data=self._data),
ignore_sbio=True)

def average(self, picks=None):
"""Compute average of epochs
Expand Down
3 changes: 2 additions & 1 deletion mne/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ def __sub__(self, evoked):
return out

def __hash__(self):
return object_hash(dict(info=self.info, data=self.data))
return object_hash(dict(info=self.info, data=self.data),
ignore_sbio=True)

def get_peak(self, ch_type=None, tmin=None, tmax=None, mode='abs',
time_as_index=False):
Expand Down
3 changes: 2 additions & 1 deletion mne/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def __exit__(self, exception_type, exception_val, trace):
def __hash__(self):
if not self._preloaded:
raise RuntimeError('Cannot hash raw unless preloaded')
return object_hash(dict(info=self.info, data=self._data))
return object_hash(dict(info=self.info, data=self._data),
ignore_sbio=True)

def _add_eeg_ref(self, add_eeg_ref):
"""Helper to add an average EEG reference"""
Expand Down
17 changes: 11 additions & 6 deletions mne/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _sort_keys(x):
return keys


def object_hash(x, h=None):
def object_hash(x, h=None, ignore_sbio=False):
"""Hash a reasonable python object
Parameters
Expand All @@ -59,6 +59,8 @@ def object_hash(x, h=None):
{dict, list, tuple, ndarray, str, float, int, None, StringIO, BytesIO}.
h : hashlib HASH object | None
Optional, object to add the hash to. None creates an MD5 hash.
ignore_sbio : bool
If True, instances of StringIO / BytesIO are ignored.
Returns
-------
Expand All @@ -70,15 +72,16 @@ def object_hash(x, h=None):
if isinstance(x, dict):
keys = _sort_keys(x)
for key in keys:
object_hash(key, h)
object_hash(x[key], h)
object_hash(key, h, ignore_sbio)
object_hash(x[key], h, ignore_sbio)
elif isinstance(x, (StringIO, BytesIO)):
# h.update(x.getvalue())
pass # XXX buggy for Raw instances for some reason...
# XXX buggy for Raw instances for some reason...
if not ignore_sbio:
h.update(x.getvalue())
elif isinstance(x, (list, tuple)):
h.update(str(type(x)).encode('utf-8'))
for xx in x:
object_hash(xx, h)
object_hash(xx, h, ignore_sbio)
elif isinstance(x, (string_types, float, int, type(None))):
h.update(str(type(x)).encode('utf-8'))
h.update(str(x).encode('utf-8'))
Expand All @@ -102,6 +105,8 @@ def object_diff(a, b, pre=''):
StringIO.
b : object
Must be same type as x1.
pre : str
String to prepend to each line.
Returns
-------
Expand Down

0 comments on commit c4f715a

Please sign in to comment.