2 from functools
import singledispatch
8 frame
= inspect
.currentframe()
9 if 'verbose' in frame
.f_back
.f_locals
:
10 verbose
= frame
.f_back
.f_locals
['verbose']
15 for s
in args
[:(len(args
)-1)]:
20 ## Generic function to hash dictionary of various types
23 ## Top level hash function with built-in hash function for str, float, int, etc
27 @hash2.register(np
.ndarray
)
28 ## Hash numpy array, hash array with pandas and return integer sum
30 # return hash(x.tobytes())
31 return np
.sum(pd
.util
.hash_array(x
))
34 ## Hash list, convert to tuple
36 return hash2(tuple(x
))
38 @hash2.register(tuple)
41 for i
in range(len(x
)):
46 ## Hash dict, loop through keys and hash each element via dispatch. Return hashed integer sum of hashes
47 def _(x
, keys
= None, verbose
= False):
48 r
= 0 # return value integer
49 if keys
is None: # allow user input of keys to hash, otherwise hash them all
53 if (verbose
): print('Hashing', key
)
57 def print_args(func
, *args
, **kwargs
):
58 # wrapper to trace function call and arguments
59 print(f
"Called: {func.__name__}")
63 for key
, value
in kwargs
.items():
64 print(f
" {key}={value}")
65 return func(*args
, **kwargs
)
67 def print_args_test():
68 def my_function(a
, b
):
71 print_args(my_function
, a
=1, b
=2)