-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAINT: stats.ContinuousDistribution: improve doc generation; fix broken doctests by making stats.Uniform
public again
#22027
Conversation
stats.Uniform
stats.Uniform
stats.Uniform
stats.Uniform
stats.Uniform
public again
They shouldn't for private objects and should for public ones, anything else is a bug. Do they get collected as tests? |
I'm not sure I follow? Not sure how to check. Take a look in scipy/scipy/stats/_distribution_infrastructure.py Line 4354 in 7f03fba
The public methods of Mixture (e.g. pdf ) don't include a docstring, so they inherit the _ProbabilityDistribution documentation. This is definitely happening, since these docs are rendered.In the examples: from scipy.stats import Uniform
# ImportError: cannot import name 'Uniform' from 'scipy.stats' (/Users/matthaberland/Desktop/scipy/scipy/stats/__init__.py) If these examples were running as doctests, I'd expect CI to fail, but it doesn't. |
So something fancy is going on with these docstrings, but as far as doctester is aware, Mixture does not have examples, so there's nothing to check. |
Either run
One caveat is that our pytest plugin skips empty examples, https://github.com/scipy/scipy_doctest/blob/main/scipy_doctest/plugin.py#L239, so not having an entry might mean it either is missed completely or the docstring exists but does not have examples. |
Oh, actually, the problem is not in the class docstring, what's missing are examples from docstrings of methods, is this correct? For one, The issue seems to be that doctesting does not collect examples from superclasses (I only took a cursory look, so the analysis below can be still incorrect or incomplete). The output of Looking through the collection chain, in the end of the day, our And it seems to miss Is this related to inherting from ABC? Taking a quick peek into the inheritance hierarchy which does not have ABCs: Adding examples to docstrings of $ git diff
diff --git a/scipy/interpolate/_bsplines.py b/scipy/interpolate/_bsplines.py
index 3d68e8d532..27a660a1f0 100644
--- a/scipy/interpolate/_bsplines.py
+++ b/scipy/interpolate/_bsplines.py
@@ -492,6 +492,9 @@ class BSpline:
Shape is determined by replacing the interpolation axis
in the coefficient array with the shape of `x`.
+ >>> 2
+ 3
+
"""
if extrapolate is None:
extrapolate = self.extrapolate
diff --git a/scipy/interpolate/_interpolate.py b/scipy/interpolate/_interpolate.py
index 7558bd7db2..6f6e84ce54 100644
--- a/scipy/interpolate/_interpolate.py
+++ b/scipy/interpolate/_interpolate.py
@@ -770,6 +770,10 @@ class _PPolyBase:
breakpoints. The polynomial intervals are considered half-open,
``[a, b)``, except for the last interval which is closed
``[a, b]``.
+
+ >>> 2
+ 3
+
""" and running Is this related to our filtering of public objects which we apply on top of the standard library An intermediate conclusion: looks like the root problem is the behavior of the standard library |
Yes. The class-level examples seem to run. One emitted a warning, causing a refguide check failure. So it's just the documentation of the methods. |
Okay, it's a scipy-doctest bug, scipy/scipy_doctest#177 Apparently, our doctest finding algorithm misses docstrings of methods defined in private parent classes. Why we did not notice is --- most likely, this is the first time in the last decade somebody wanted to inherit a method with a docstring example from a private parent class. Possible ways out:
|
@steppi do you use |
Yes, I use |
I observed one failure for
Two for
no failures for |
OK, the failures in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I've confirmed that
python dev.py smoke-docs -t scipy/stats/_probability_distribution.py
passes now.
…en doctests by making `stats.Uniform` public again (scipy#22027) * MAINT: stats.ContinuousDistribution: revert to dynamic doc generation * ENH: stats.Uniform: add uniform distribution * BUILD: stats: remove reference to eliminated _new_distribution_docs.json * MAINT: stats.Uniform: improvements * MAINT: integrate.tanhsinh: fix regression * DOC: stats._distribution_infrastructure: fix doctests [skip ci]
Reference issue
gh-21050
What does this implement/fix?
The method documentation of
ContinuousDistribution
was written whenUniform
was public, so many of the examples usedUniform
to illustrate a point.Uniform
was temporarily made private, breaking the examples, but we didn't notice the problem because apparently these doctests aren't running1. This PR fixes the problem by makingUniform
public again (taking the opportunity to fill out the implementation).Also eliminates the code that was caching/loading the docs to/from a
json
file rather than generating them at import time. If we need to add something like that back, we can, but it's fast enough right now that the complexity is not warranted. We still need to do something about the fact that method documentation is rendered separately for every subclass of_ProbabilityDistribution
but that is also something that can wait because it is not a big problem unless we have many distributions.Footnotes
Not sure what that's about; if we can't figure it out here, I'll open a separate issue. Maybe something to do with the docstrings being inherited from an ABC? ↩