Issue with np.bool Deprecation in Theano and PyMC3

I am encountering an issue related to the deprecation of np.bool in NumPy version 1.20.0 and later, which seems to be affecting my PyMC3 code due to its dependency on Theano. When I try to run my script, I get the following error:

AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.

Here is the relevant part of the stack trace:

File "C:\Users\XXX\anaconda3\Lib\site-packages\theano\scalar\basic.py", line 2412, in __init__
    self.ctor = getattr(np, o_type.dtype)

I understand that this is a known issue and has been addressed in later versions of Theano. However, I am still encountering this issue and am unsure how to proceed. Here are the versions of the relevant libraries I am using:

  • PyMC3: [5.9.0]
  • NumPy: [1.26.0]
  • ArviZ: [0.16.1]

when downgrading to numpy==1.19.5:

Additional Issue After Downgrading NumPy

After attempting to resolve the initial issue by downgrading NumPy to version 1.19.5, I encountered another error:

AttributeError: module 'arviz' has no attribute 'from_pymc3'. Did you mean: 'from_pyro'?

Here is the relevant part of the stack trace:

File "C:\Users\XXX\anaconda3\Lib\site-packages\pymc3\sampling.py", line 639, in sample
    idata = arviz.from_pymc3(trace, **ikwargs)

It seems like there might be an issue with the ArviZ version I am using (0.16.1) and its compatibility with PyMC3 version 3.11.4, particularly regarding the from_pymc3 function. I have tried to ensure that all libraries are updated to their latest versions, but this error persists.

Any insights or suggestions on how to navigate this new error while also addressing the initial np.bool deprecation issue would be immensely helpful. Thank you again for your time and assistance!

I am not completely sure about wheather you are using PyMC3 3.11.4 or PyMC 5.9.0 from the question, but the error messages use theano and pymc3 (instead of pymc) so it is probable the first one.

PyMC3 3.11.4 was released in August 2021 so I would not expect it to work with latest NumPy/ArviZ/other libraries of the scientific python ecosystem. There was a patch release in March 2022 but it is not being developed anymore. If you want to use the latest versions of the libraries I recommend you use a recent version of pymc. Otherwise your best bet is to install versions that were released around the same time (because those are the versions that CI was testing), for ArviZ for example, you’d want something like the 0.12.0 version.

The PyMC blog has some posts like the 4.0 release announcement (and dropping of both Theano and the 3 as part of the library name), an overview of the library history and its main changes in “PyMC: Past, Present and Future” post and some others in case you are interested in reading more on these changes.

2 Likes