Conversation
TimothyWillard
left a comment
There was a problem hiding this comment.
Let's rename the test files from test_ObjectName.py to test_object_name_class.py to match other test files. For future reference I think we only need to unit test custom field/model validators, we can trust that the folks at pydantic have throughly unit tested validations provided by their package.
|
@TimothyWillard , just committed with your suggestions. Let me know if you want each of the |
There was a problem hiding this comment.
Looks good to me. An example for DistributionABC.sample doesn't make much sense because it's an ABC so we can pass on that. Not exactly sure how the documentation renders here, but I think DistributionABC.sample's docstring applies to all subclasses here so we can also pass on that.
21b28c4 to
74713e2
Compare
Added a module for representing distributions that can be used throughout gempyor. Started with `DistributionABC` as and abstract base for all distributions. Implemented `FixedDistribution` and `NormalDistribution` using that ABC. Finally, exposed a field discriminated type to easily create distributions from config.
Added a representation for uniform distributions to `gempyor.distributions`.
Added a representation of a poisson distribution to `gempyor.distributions`
Added a representation for binomial distribution to `gempyor.distributions`.
Added a lognormal distribution to `gempyor.distributions`.
Added a truncated normal distribution to `gempyor.distributions`.
Added a representation for gamma distributions to `gempyor.distributions`
Added a representation for Weibull distributions to `gempyor.distributions`. Also, fixed a return type hint error.
Unit tests and validation for the `NormalDistribution` class in `gempyor_pkg/tests/distributions/`
Unit tests and validation for the `FixedDistribution` class in `gmepyor_pkg/tests/distributions/`. Also removal of an unused parameter in the `FixedDistribution` `.sample()` method.
Unit tests and validation for the `UniformDistribution` class in `gempyor_pkg/tests/distributions/`. Also linting from a previous commit I forgot to add.
Unit tests and validation for the `LognormalDistribution` class in `gempyor_pkg/tests/distributions/` + a fix for an issue that I created in `2c5fce5`
Add tests for the `TruncatedNormalDistribution` class from `gempyor.distributions`. Also, formatting fixes and bound fixes.
Unit tests and validation for `PoissonDIstribution` class in `gempyor.distributions`. Also, formatting and bounds fixes.
Take 10 samples rather than 1 to reduce the risk of an identical series of samples being drawn (causing a test failure when arrays are compared).
TimothyWillard
left a comment
There was a problem hiding this comment.
Minor comment about not wanting the DistributionABC.rng property to be public, but otherwise looks good to me.
use pydantic capabilities for default_factory Co-authored-by: Timothy Willard <9395586+TimothyWillard@users.noreply.github.com>
There was a problem hiding this comment.
Looking basically right. A few definite TODOs, but two items for discussion?
@emprzy @TimothyWillard what are your thoughts re 1) testing the initializer and 2) testing the output ranges?
depending how those opinions go, there's a bit of stripping out to do alongside the other fixes.
flepimop/gempyor_pkg/tests/distributions/test_beta_distribution_class.py
Outdated
Show resolved
Hide resolved
flepimop/gempyor_pkg/tests/distributions/test_binomial_distribution_class.py
Outdated
Show resolved
Hide resolved
flepimop/gempyor_pkg/tests/distributions/test_beta_distribution_class.py
Show resolved
Hide resolved
flepimop/gempyor_pkg/tests/distributions/test_truncatednormal_distribution_class.py
Show resolved
Hide resolved
flepimop/gempyor_pkg/tests/distributions/test_poisson_distribution_class.py
Show resolved
Hide resolved
Re:
|
Agree about item 1). Item 2), It would be pretty easy to add tests for ranges, if we want to do that. I see no harm in implementing them if we think it would add value. |
Move shape tests to something that is tested at the `DistributionsABC` level, small verbiage changes in parametrization, re-naming of `DistributionsABC` testing file.
flepimop/gempyor_pkg/tests/distributions/test_poisson_distribution_class.py
Outdated
Show resolved
Hide resolved
flepimop/gempyor_pkg/tests/distributions/test_uniform_distribution_class.py
Outdated
Show resolved
Hide resolved
flepimop/gempyor_pkg/tests/distributions/test_truncatednormal_distribution_class.py
Outdated
Show resolved
Hide resolved
flepimop/gempyor_pkg/tests/distributions/test_distributions_common.py
Outdated
Show resolved
Hide resolved
flepimop/gempyor_pkg/tests/distributions/test_poisson_distribution_class.py
Show resolved
Hide resolved
flepimop/gempyor_pkg/tests/distributions/test_truncatednormal_distribution_class.py
Show resolved
Hide resolved
| n: int = Field(..., gt=0) | ||
| p: float = Field(..., gt=0.0, lt=1.0) |
There was a problem hiding this comment.
mmm, shouldn't these be ge, le still? and the == part is now being checked by the edge cases bit?
There was a problem hiding this comment.
Do you not want n == 0 and (p == 0 or p == 1) to be considered an edge case?
There was a problem hiding this comment.
yes - but isn't gt / lt going to strictly disallow them, irrespective of allow_edge_cases?
There was a problem hiding this comment.
should be exercising the allowed vs disallowed edge cases, right?
There was a problem hiding this comment.
oh hm great point. I'll fix that.
Change to correct operator (`ge` and `le`), update tests accordingly
Describe your changes.
This pull request creates a
distributionsmodule that contains classes with sampling methods for a variety of distributions, and corresponding tests/validation for these classes in a new directory,gempyor_pkg/tests/distributions/.Does this pull request make any user interface changes? If so please describe.
No user interface changes.
What does your pull request address? Tag relevant issues.
This pull request was spun out of #570, and addresses what is requested in #573 (@MacdonaldJoshuaCaleb , see Gamma, Weibull, and Beta distributions added to
distributions.py).