Skip to content

BUG: Several distributions fail in Python 3.13 due to deprecated class property support #7551

Closed
@thomasaarholt

Description

@thomasaarholt

Describe the issue:

Python 3.13 breaks backward compatibility on chaining classmethods and property decorators, citing that it was a flawed approach. See the first bullet point here, and another article here going in to workarounds.

The pattern used in pymc, which is now failing, is this from distribution.py:

class SymbolicRandomVariable(MeasurableOp, OpFromGraph):
    ...

    @_class_or_instancemethod
    @property
    def ndims_params(cls_or_self) -> Sequence[int] | None:

This pattern occurs 5 times in the codebase, all in distribution.py.

Reproduceable code example:

import pymc as pm

with pm.Model() as model:
    pm.ExGaussian("foo", mu=1, sigma=2, nu=5)

Error message:

WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Traceback (most recent call last):
  File "/Users/thomas/repos/pymc-typed-distributions/run.py", line 4, in <module>
    x = pm.ExGaussian("foo", mu=1, sigma=2, nu=5)
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/distribution.py", line 508, in __new__
    rv_out = cls.dist(*args, **kwargs)
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/continuous.py", line 2945, in dist
    return super().dist([mu, sigma, nu], **kwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/distribution.py", line 577, in dist
    rv_out = cls.rv_op(*dist_params, size=create_size, **kwargs)
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/continuous.py", line 2862, in rv_op
    size = implicit_size_from_params(mu, sigma, nu, ndims_params=cls.ndims_params)
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/shape_utils.py", line 464, in implicit_size_from_params
    for param, ndim in zip(params, ndims_params):
                       ~~~^^^^^^^^^^^^^^^^^^^^^^

PyMC version information:

pymc 5.17.0, installed via uv/pip

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