make every argument hached

This commit is contained in:
fx_kirin
2020-01-08 12:45:30 +09:00
parent 0cbe7efcd1
commit 3f8750361a
+26 -2
View File
@@ -152,10 +152,34 @@ class _PickleCore(_BaseCore):
return key, self._get_cache().get(key, None)
def get_entry(self, args, kwds):
key = args + tuple(sorted(kwds.items()))
# print('key type={}, key={}'.format(type(key), key))
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):
try:
import pandas
if isinstance(value, pandas.DataFrame):
return(pandas.util.hash_pandas_object(value))
except ImportError:
pass
if hasattr(value, "to_bytes"): # For numpy
try:
return hash(value.to_bytes())
except TypeError:
pass
elif hasattr(value, "__iter__"): # For iterators
hash_array = []
for elem in value:
hash_array.append(value)
return tuple(hash_array)
elif hasattr(value, "items"): # For dict
hash_array = []
for key, elem in value.items:
hash_array.append(key)
hash_array.append(elem)
return tuple(hash_array)
return hash(value)
def set_entry(self, key, func_res):
with self.lock:
cache = self._get_cache()