Skip to content

Conversation

cluhmann
Copy link
Member

@cluhmann cluhmann commented Jun 17, 2022

Fixes #5716, renaming pm.Constant as pm.DiractDelta. This is currently a basic find-and-replace in both the source and tests. In the original issue, there was mention of adding a user warning about use of this distribution (i.e., sampling is hard). However, pm.Constant had no __new__ method, so I wasn't sure where to add it. Happy to do so once I know where.

@codecov
Copy link

codecov bot commented Jun 17, 2022

Codecov Report

Merging #5903 (1d7a52f) into main (3bf95ce) will decrease coverage by 0.00%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5903      +/-   ##
==========================================
- Coverage   89.50%   89.49%   -0.01%     
==========================================
  Files          73       73              
  Lines       13267    13275       +8     
==========================================
+ Hits        11874    11880       +6     
- Misses       1393     1395       +2     
Impacted Files Coverage Δ
pymc/distributions/__init__.py 100.00% <ø> (ø)
pymc/distributions/discrete.py 99.21% <85.71%> (-0.52%) ⬇️

@twiecki
Copy link
Member

twiecki commented Jun 17, 2022

I think we should deprecate.

@ricardoV94
Copy link
Member

I think we should deprecate.

What do you mean, have an alias with a warning for a while?

@twiecki
Copy link
Member

twiecki commented Jun 17, 2022

Yeah.

@ricardoV94
Copy link
Member

Yeah.

I agree

@ricardoV94
Copy link
Member

ricardoV94 commented Jun 17, 2022

In the original issue, there was mention of adding a user warning about use of this distribution (i.e., sampling is hard). However, pm.Constant had no __new__ method, so I wasn't sure where to add it. Happy to do so once I know where.

Let's not add it to the new renamed distribution, hopefully the name is good enough to dissuade people. We could add a warning message in docstrings.

For the deprecation, you will have to do something like:

class Constant:
  def __new__(cls, *args, **kwargs):
    warnings.warn("bla bla blah", FutureWarning)
    return DiracDelta(*args, **kwargs)

  @classmethod
  def dist(cls, *args, **kwargs):
    warnings.warn("blah blah blah", FutureWarning)
    return DiracDelat.dist(*args, **kwargs)

@OriolAbril
Copy link
Member

@cluhmann
Copy link
Member Author

API docs at https://github.com/pymc-devs/pymc/blob/main/docs/source/api/distributions/discrete.rst also need to be updated

Should the now-deprecated pm.Constant be documented at all or should it be hidden to (further) discourage its use?

@ricardoV94
Copy link
Member

API docs at https://github.com/pymc-devs/pymc/blob/main/docs/source/api/distributions/discrete.rst also need to be updated

Should the now-deprecated pm.Constant be documented at all or should it be hidden to (further) discourage its use?

Hidden I think

def test_constantdist(self):
check_logp(Constant, I, {"c": I}, lambda value, c: np.log(c == value))
check_logcdf(Constant, I, {"c": I}, lambda value, c: np.log(value >= c))
with pytest.warns(FutureWarning):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with pytest.warns(FutureWarning):
with pytest.warns(FutureWarning, match="..."):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can be at the end of the file, it shouldn't be in this generic class that checks for logp/logcdf stuff

Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ricardoV94 ricardoV94 merged commit f9b749b into pymc-devs:main Jun 18, 2022
@michaelosthege
Copy link
Member

Hehe, I'm on the train and was just reading through the updates here, wanting to review..
Suddenly the "open" changes to "merged". Okay :p

@cluhmann cluhmann deleted the constantrename branch August 11, 2022 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename Constant to DiracDelta and add docstring warning about sampling it
5 participants