I am wondering, how come hashing e.g. strings in an np object[] produces expected results:
>>> hashlib.sha256(np.array(['asdfda'], dtype=object)).hexdigest()
'6cc08fd2542235fe8097c017c20b85350899c81616db8cb59045022663e3cee1'
>>> hashlib.sha256(np.array(['asd'+'fda'], dtype=object)).hexdigest()
'6cc08fd2542235fe8097c017c20b85350899c81616db8cb59045022663e3cee1'
That is, the hashing takes into account the actual object value, not a just the pointer value, as stored in the array. (Those strings would definitely have different pointers.)
hashlib
methods seem to accepting objects supporting some 'buffer API', as not doing so produces TypeError: object supporting the buffer API required
.
Does that mean that buffer API implementation for numpy's ndarray does not return an array of pointers, but rather somehow an array of strings, or in other words how does hashlib.hash_algorithm
get to those stored strings of characters?