pymc icon indicating copy to clipboard operation
pymc copied to clipboard

BUG: pm.Data does not accept dtype argument

Open ricardoV94 opened this issue 1 year ago • 1 comments

@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

ricardoV94 avatar Apr 22 '24 17:04 ricardoV94

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.

michaelosthege avatar May 02 '24 14:05 michaelosthege