Repository navigation
DOC, TST: enable doctests - #12253
Conversation
|
I'm not sure I like the use of ellipsis for floats in the docstrings, as they make the reprs non-eval-able - although I don't know what the right answer there is. Lots of other good stuff here, thanks! |
I agree, that doesn't look quite right. Using the refguide checker as discussed in gh-9415 should fix that, it doesn't require exact repr equality but just that numerical values are within a given tolerance (uses
+1 |
|
I also wonder about just creating a lightweight doctest flag for the floating point comparisons rather than copying over the entire I guess one issue here is that NumPy can't depend on SciPy, so it would almost be better if the refguide checker base code lived in NumPy instead, and perhaps even better still if there were a general scientific refguide checker maintained externally to both for use in the ecosystem. It is a little ugly to have two copies of |
|
Also worth noting that Indeed, we also have / have had our own custom ouput checkers, subclassed from |
780b66e to
0de9b38
Compare
I'm afraid you'd be reinventing the wheel mostly. There's a reason for the SciPy tool being complex....
Agreed, ideally we'd have this as a standalone package. Otherwise, syncing changes in script manually is also fine, not too big a deal (we do it with, e.g., Thinking about it some more, beyond NumPy/SciPy effort - the package is a good idea. It would save the whole ecosystem a lot of time. For example, the reason the printing changes in NumPy 1.14.x were so painful for everyone was that |
|
Agreed a small package living in the numpy org would be best. Allowing for per-project skip lists etc does not souns difficult. Whether the package can be used as an external dependency or will it need to be vendored (like numpydoc in scipy) remains to be seen --- I guess one needs to try adapring it for numpy and see :--). |
2c9fa3f to
d6b923e
Compare
|
Now working with a crudely-adjusted version of SciPy's Added the refguide check tentatively to Azure CI in this branch -- it sould fail with around 4400 lines of problematic output (it was 6000+ earlier today). One thing I don't get is the magic behind printing array objects resulting in the output of |
There was a problem hiding this comment.
print() will produce random here and elsewhere when handling an array
395f251 to
b2a20df
Compare
|
b2a20df to
0e829fa
Compare
787a96b to
26b28ed
Compare
|
|
|
That's a strange failure. Hmm.... I've restarted the azure builds. |
|
The actual numbers look fine and I don't see any invalid values, so I suspect the warning came from somewhere else and somehow wasn't handled until that test. But it is worrisome. Do you know if the tests are threaded? |
|
What happens if the tests encounter an invalid value in the doctests? In the "official" tests we suppress warnings when they don't matter. |
|
I think refguide is pretty careful about catching things. We're only running doctests in one of the CI jobs though, and that wasn't the one that was failing. I haven't adjusted any linear algebra backend thread count settings, but note that our Windows builds in Azure have only recently started using openblas, and if there are 32/64-bit new openblas version builds we need to start pointing to, that might be a factor I suppose. Maybe I should bump to the appropriate openblas builds from the wheels after recent release / bump. |
|
I'm a bit wary about trying to get this into 1.16, so giving it a 1.17 milestone so we have time to see and deal with any issues that may arise. It would probably be OK, maybe even desirable, to put in the docstring fixes and just leave the testing turned off until 1.17. Thoughts? |
|
Delay on release sounds reasonable I suppose. Less keen on merging the doc fixes separately, especially if i.e., someone fixes the matmul docstring separate from this PR and then I end up having to resolve merge conflicts on this branch which marks that same docstring as SKIP for now & maybe even discover that their fix isn't quite right, and so on... If people want to go that route, then I'd strongly suggest making 1.16 docstring-targeted fixes directly in this PR so they are subjected to the refguide CI immediately, etc. |
There was a problem hiding this comment.
It is important to check that this list of public NumPy submodules is reasonably complete. I just noticed that lib.recfunctions was previously absent, so refguide_check wasn't executing docstrings in that module, some of which were the subject of reviewer comments (probably diffs originated from before refguide switch when I was using vanilla doctests).
Also, even if I add lib.recfunctions, not all function docstrings therein are executed -- it seems I also need to add functions to __all__ in the module, but I'm hesitant do start doing that more broadly without reviewer approval first. Thoughts on this?
There was a problem hiding this comment.
I think skipping private functions, which should be everything not in __all__ with, or without the underscore, would probably be OK. If they are not intended to be private then they should be added. That said, lib.recfunctions has always been an oddball, as it is not imported at the top level.
@shoyer Not all functions in lib.recfunctions have dispatchers.
There was a problem hiding this comment.
@charris looking through lib.recfunctions the functions without dispatchers seem to not take arrays as inputs (e.g., get_fieldspec). So these properly don't have dispatchers -- there's no array argument on which to call a dispatcher method (we don't have duck-typed dtypes). Let me know if there's anything in particular that you think I missed, though...
|
I was thinking of merging as is, but with the doctests turned off. You could then open another PR, turn it on, and continue making fixes. The advantage would be similarity between 1.16 and 1.17, the disadvantage would be loss of all the comments, which might be too high a price to pay. |
There was a problem hiding this comment.
I think we can remove the redundant >>> # here and keep these as normal text.
There was a problem hiding this comment.
I think you're looking at an outdated diff -- there's even a badge above indicating as such.
I checked out numpy/lib/mixins from latest master so there shouldn't be a diff from your original code. That said, doctests probably aren't even running for lib.mixins until someone, probably me, adds it to the list of public modules in refguide.
There was a problem hiding this comment.
can we preserve the line breaks I had before? That helped readability.
There was a problem hiding this comment.
The code was reverted to master branch status already based on your previous comments.
There was a problem hiding this comment.
Oops -- sorry about these outdated comments! I had drafted them before but not sent them -- and they just got sent along with my latest response to Chunk!
There was a problem hiding this comment.
@charris looking through lib.recfunctions the functions without dispatchers seem to not take arrays as inputs (e.g., get_fieldspec). So these properly don't have dispatchers -- there's no array argument on which to call a dispatcher method (we don't have duck-typed dtypes). Let me know if there's anything in particular that you think I missed, though...
Oh, my bad... |
|
At some point |
There was a problem hiding this comment.
I think there's enough good stuff here that we should go ahead and merge - this diff is too large to catch everything in, and even if there are a few points of disagreement, the docstrings are overall way more accurate.
The cost will at worst be intermittent CI failures, which we can either catch quickly, or resolve temporarily by disabling doctests again while we sort them out.
* ported the refguide_check module from SciPy for usage in NumPy docstring execution/ verification; added the refguide_check run to Azure Mac OS CI * adjusted NumPy docstrings such that refguide_check passes
…sses in any case now.
* restored regression comment in numpy/core/defchararray.py * fixed the dimensionality of the z array in all() docstring in numpy/core/fromnumeric.py; this isn't detected because it is in-line with variable memory addresses which are tagged as variable for refguide * byte_bounds() docstring adjusted to reflect non-variable dtype after reviewer requested removal of complex dtype * restore an original comment in matmul docstring, as requested by reviewer
* reviewer requested that the cases where I switched from free-floating comments to `>>> # comments` be reverted to free-floating in docstrings
* added lib.recfunctions to refguide PUBLIC_SUBMODULES, as the doctests were otherwise not getting executed * fixed a failing doctest in recfunctions after above activation
c658b03 to
28f8a85
Compare
|
Ok, I rebased and force-pushed. If the CI remains all-green I suppose we could go for merge if others are ok with a sort of "2 steps forward, 1 step backward" approach, with smaller / focused PRs to follow. I think @stefanv wants a "wish list" for refguide features/ fixes. There has been some discussion of eventually extracting to its own package for the community, but one thing at a time. The current apparent opt-in instead of opt-out model seems a little annoying. On that note, I do see a few posts floating around online about combining coverage with doctests, one from Raymond Hettinger, and another pytest issue apparently indicating that this does actually work for doctests + coverage, but people aren't sure how the magic works. |
|
Thanks Tyler. |
Related to #9415,
but using doctests proper--this is pretty painful, although I'm making progress & there are some real issues in the docstrings.Using this command locally:
python runtests.py -- --doctest-modules --ignore=numpy/ma/version.py --ignore=numpy/f2py/__main__.py --ignore=numpy/distutils/msvc9compiler.py --ignore=numpy/core/generate_numpy_api.py --ignore=numpy/core/cversions.py --ignore=numpy/testing -n 3 >& log.txtTo do: