Skip to content

BUG: Suppress numpy warnings in PyTensor Elemwise perform #1577

@asifzubair

Description

@asifzubair

Describe the issue:

This is not really a bug, but a request to suppress numpy warnings when doing some valid operations. These warnings came up when working on the CensovedRV. @ricardoV94 provided some context for them:

We used to constant-fold in C which doesn't have such warnings, and now we do in Python.

Reproduceable code example:

import numpy as np
import pymc as pm
from pymc import logcdf
norm = pm.Normal.dist(0, 1)
logcdf(norm, np.inf).eval()
logcdf(norm, -np.inf).eval()

Warning message:

>>> logcdf(norm, np.inf).eval()
/opt/conda/envs/pymc-dev/lib/python3.13/site-packages/pytensor/tensor/elemwise.py:710: RuntimeWarning: invalid value encountered in subtract
  variables = ufunc(*ufunc_args, **ufunc_kwargs)
array(-0.)
>>> logcdf(norm, -np.inf).eval()
/opt/conda/envs/pymc-dev/lib/python3.13/site-packages/pytensor/tensor/elemwise.py:710: RuntimeWarning: divide by zero encountered in log1p
  variables = ufunc(*ufunc_args, **ufunc_kwargs)
/opt/conda/envs/pymc-dev/lib/python3.13/site-packages/pytensor/tensor/elemwise.py:710: RuntimeWarning: divide by zero encountered in log
  variables = ufunc(*ufunc_args, **ufunc_kwargs)
array(-inf)

PyMC version information:

I used our docker environment for testing.

Python 3.13.5 | packaged by conda-forge
>>> pm.__version__
'5.25.1+9.g09603234f'
>>> pytensor.__version__
'2.32.0'

Context for the issue:

Personally, needed to handle these warnings when writing tests. It's a bit annoying but not a show stopper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions