nanograv / enterprise

ENTERPRISE (Enhanced Numerical Toolbox Enabling a Robust PulsaR Inference SuitE) is a pulsar timing analysis code, aimed at noise analysis, gravitational-wave searches, and timing model analysis.
https://enterprise.readthedocs.io
MIT License
64 stars 65 forks source link

Many exceptions in enterprise/signals/parameter.py cannot be triggered #364

Open vhaasteren opened 9 months ago

vhaasteren commented 9 months ago

The parameter.py class contains quite a few lines that are not unit tested. When adding the PPF functions I had to look into this (because of the codecov), and it turns out many potential exceptions in the original code are testing for the wrong things and cannot be triggered.

Example:

    def get_logpdf(self, value=None, **kwargs):
        # RvH: This exception cannot be triggered
        if not isinstance(self, Parameter):
            raise TypeError("You can only call get_logpdf() on an " "instantiated (named) Parameter.")

This TypeError supposedly is thrown when you use the class factory to obtain a Parameter, such as with par = Uniform(pmin=0, pmax=1). If you then try to use par.get_logpdf(0.5) this should not work, because the class is not instantiated (named). Instead, you need to do: par = Uniform(pmin=0, pmax=1)('testpar').

Thing is, you can never call get_logpdf using the class definition, because you are then not passing self to the function. So that exception can never be triggered. This kind of thing happens a lot in the parameter module. A solution would be to just remove all the exceptions that cannot be triggered.