diff --git a/cachier/pickle_core.py b/cachier/pickle_core.py index f32390e..f7cac16 100644 --- a/cachier/pickle_core.py +++ b/cachier/pickle_core.py @@ -152,10 +152,10 @@ class _PickleCore(_BaseCore): return key, self._get_cache().get(key, None) def get_entry(self, args, kwds): - key = tuple(self.hash_args(key) for key in args + tuple(sorted(kwds.items()))) + key = tuple(self._hash_args(key) for key in args + tuple(sorted(kwds.items()))) return self.get_entry_by_key(key) - def hash_args(self, value): + def _hash_args(self, value): try: import pandas if isinstance(value, pandas.DataFrame): @@ -165,15 +165,16 @@ class _PickleCore(_BaseCore): if hasattr(value, "tobytes"): # For numpy return hash(value.tobytes()) if hasattr(value, "__iter__"): # For iterators - hash_array = [] - for elem in value: - hash_array.append(value) - return tuple(hash_array) + if isinstance(value, (list, tuple)): + hash_array = [] + for elem in value: + hash_array.append(self._hash_args(elem)) + return tuple(hash_array) if hasattr(value, "items"): # For dict hash_array = [] for key, elem in value.items: hash_array.append(key) - hash_array.append(elem) + hash_array.append(self._hash_args(elem)) return tuple(hash_array) return hash(value)