BUG: pm.Data does not accept dtype argument
@michaelosthege and I found out that the latest changes create issues when using pm.ConstantData (or pm.Data) and setting a dtype explicitly. We don't understand why because pytensor.shared has no problem with the dtype argument.
Here is an example:
with pm.Model():
pm.Data("b", [True, False], dtype=bool)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "C:\Users\osthege\AppData\Local\mambaforge\envs\dibecs_6.13.0\lib\site-packages\pymc\data.py", line 420, in Data
x = pytensor.shared(arr, name, **kwargs)
File "C:\Users\osthege\AppData\Local\mambaforge\envs\dibecs_6.13.0\lib\site-packages\pytensor\compile\sharedvalue.py", line 202, in shared
var = shared_constructor(
File "C:\Users\osthege\AppData\Local\mambaforge\envs\dibecs_6.13.0\lib\functools.py", line 889, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
TypeError: tensor_constructor() got an unexpected keyword argument 'dtype'
Do you have any idea why this is happening? Thanks in advance for your help!
Originally posted by @lhelleckes in https://github.com/pymc-devs/pymc/issues/7047#issuecomment-2070305967
This conversion given in #7257 is a good example for the solution that @lhelleckes and I just discussed:
Adding a convert_observed_data(value, dtype: Optional=None) option which gets priority would allow the line linked above to enforce the type and thereby avoid the casting.