Skip to content

BUG: Not working with numpy 2+ (np.obj2sctype was removed in the NumPy 2.0 release.) #7592

Closed
@mauhcs

Description

@mauhcs

Describe the issue:

When importing pymc with import pymc as pm I get the error message:

AttributeError:np.obj2sctypewas removed in the NumPy 2.0 release. Usenp.dtype(obj).type instead.
(see full error message below).

I think the message is pretty clear, pymc does not support Numpy 2.0 at the moment.

Do we have any plans to support it?

Reproduceable code example:

# you just need to import pymc with numpy 2.1.3 of higher to get the error
import pymc as pm

Error message:

----> 1 import pymc as pm

File ~/miniconda3/lib/python3.12/site-packages/pymc/__init__.py:46
     41     augmented = f"{augmented} -fno-unwind-tables -fno-asynchronous-unwind-tables"
     43     pytensor.config.gcc__cxxflags = augmented
---> 46 __set_compiler_flags()
     48 from pymc import _version, gp, ode, sampling
     49 from pymc.backends import *

File ~/miniconda3/lib/python3.12/site-packages/pymc/__init__.py:29, in __set_compiler_flags()
     27 def __set_compiler_flags():
     28     # Workarounds for PyTensor compiler problems on various platforms
---> 29     import pytensor
     31     current = pytensor.config.gcc__cxxflags
     32     augmented = f"{current} -Wno-c++11-narrowing"

File ~/miniconda3/lib/python3.12/site-packages/pytensor/__init__.py:118
    114     return as_tensor_variable(x, **kwargs)
    117 # isort: off
--> 118 from pytensor import scalar, tensor
    119 from pytensor.compile import (
    120     In,
    121     Mode,
   (...)
    127     shared,
    128 )
    129 from pytensor.compile.function import function, function_dump

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/__init__.py:103
     99     return len(var.data)
    102 import pytensor.tensor.exceptions
--> 103 import pytensor.tensor.rewriting
    104 from pytensor.gradient import grad, hessian, jacobian
    106 # adds shared-variable constructors

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/rewriting/__init__.py:1
----> 1 import pytensor.tensor.rewriting.basic
      2 import pytensor.tensor.rewriting.blas
      3 import pytensor.tensor.rewriting.blas_c

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/rewriting/basic.py:43
     34 from pytensor.graph.rewriting.basic import (
     35     NodeRewriter,
     36     RemovalNodeRewriter,
   (...)
     40     node_rewriter,
     41 )
     42 from pytensor.graph.rewriting.db import RewriteDatabase
---> 43 from pytensor.raise_op import Assert, CheckAndRaise, assert_op
     44 from pytensor.tensor.basic import (
     45     Alloc,
     46     AllocEmpty,
   (...)
     64     zeros_like,
     65 )
     66 from pytensor.tensor.elemwise import DimShuffle, Elemwise

File ~/miniconda3/lib/python3.12/site-packages/pytensor/raise_op.py:14
     12 from pytensor.link.c.type import Generic
     13 from pytensor.scalar.basic import ScalarType
---> 14 from pytensor.tensor.type import DenseTensorType
     17 class ExceptionType(Generic):
     18     def __eq__(self, other):

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/type.py:801
    796         dtype = config.floatX
    798     return TensorType(dtype=dtype, shape=shape, **kwargs)(name=name)
--> 801 cscalar = TensorType("complex64", ())
    802 zscalar = TensorType("complex128", ())
    803 fscalar = TensorType("float32", ())

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/type.py:105, in TensorType.__init__(self, dtype, shape, name, broadcastable)
    103     self.dtype = config.floatX
    104 else:
--> 105     if np.obj2sctype(dtype) is None:
    106         raise TypeError(f"Invalid dtype: {dtype}")
    108     self.dtype = np.dtype(dtype).name

File ~/miniconda3/lib/python3.12/site-packages/numpy/__init__.py:400, in __getattr__(attr)
    397     raise AttributeError(__former_attrs__[attr], name=None)
    399 if attr in __expired_attributes__:
--> 400     raise AttributeError(
    401         f"`np.{attr}` was removed in the NumPy 2.0 release. "
    402         f"{__expired_attributes__[attr]}",
    403         name=None
    404     )
    406 if attr == "chararray":
    407     warnings.warn(
    408         "`np.chararray` is deprecated and will be removed from "
    409         "the main namespace in the future. Use an array with a string "
    410         "or bytes dtype instead.", DeprecationWarning, stacklevel=2)

AttributeError: `np.obj2sctype` was removed in the NumPy 2.0 release. Use `np.dtype(obj).type` instead.

PyMC version information:

pip install pymc
versions:
pymc-5.15.0
numpy-2.1.3

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions