DOC: Fix quickstart doc to pass refguide#15703
Conversation
Fix printing of arrays. Add doctest flag +IGNORE_EXCEPTION_DETAIL. Fix view example with "c.base is a" by declaring "a" without reshaping.
Co-Authored-By: Eric Wieser <[email protected]>
Co-Authored-By: Eric Wieser <[email protected]>
Co-Authored-By: Eric Wieser <[email protected]>
Co-Authored-By: Eric Wieser <[email protected]>
Co-Authored-By: Eric Wieser <[email protected]>
|
Hi @eric-wieser I actually go through the failures from refguide_check.py and submit the PR when it passes. Do you run a style checker for these whitespace issues? |
|
What you're seeing is that refguide only cares about the difference between no whitespace and some whitespace, rather than distinguishing different amounts of whitespace. We changed the formatting of arrays back in 1.13, and a lots of the docs do not reflect that. What I'd suggest you do in future is rerun the failing examples in a shell and pasting the exact output, rather than just tweaking the output to pass. |
Co-Authored-By: Eric Wieser <[email protected]>
doc/source/user/quickstart.rst
Outdated
| Traceback (most recent call last): | ||
| File "<stdin>", line 1, in ? | ||
| ... | ||
| IndexError: index (3) out of range (0<=index<=2) in dimension 0 |
There was a problem hiding this comment.
This error message isn't accurate any more - can you update it to be correct?
doc/source/user/quickstart.rst
Outdated
|
|
||
| # not what we want | ||
| >>> a[s] | ||
| >>> a[s] # doctest: +IGNORE_EXCEPTION_DETAIL |
There was a problem hiding this comment.
Pretty sure this is not needed if you fix the error message below
|
copy-pasting every line of the file took quite long. I tested another method: I removed the NORMALIZE_WHITESPACE option in the pytest.ini file and run pytest on the rst file. This picks all whitespace errors so I could focus on those failures. I'll prepare a PR after reviewing the changes manually though. pytest does not accept the "may vary" flags, etc, so there was a bit of a game to play. |
doc/source/user/quickstart.rst
Outdated
| >>> a += b # b is not automatically converted to integer type | ||
| >>> a += b # b is not automatically converted to integer type # doctest: +IGNORE_EXCEPTION_DETAIL | ||
| Traceback (most recent call last): | ||
| ... | ||
| numpy.core._exceptions.UFuncTypeError: Cannot cast from dtype('float64') to dtype('int64') # IGNORE_EXCEPTION_DETAIL | ||
| numpy.core._exceptions.UFuncTypeError: Cannot cast from dtype('float64') to dtype('int64') |
There was a problem hiding this comment.
Is this necessary? What error message is refguide expecting?
There was a problem hiding this comment.
The previous version returns
Traceback (most recent call last):
File "/usr/lib/python3.7/doctest.py", line 1329, in __run
compileflags, 1), test.globs)
File "<doctest quickstart.rst[6]>", line 1, in <module>
a += b # b is not automatically converted to integer type
numpy.core._exceptions.UFuncTypeError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
/opt/default-py3-env/lib/python3.7/site-packages/numpy/core/_asarray.py:136: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
return array(a, dtype, copy=False, order=order, subok=True)There was a problem hiding this comment.
The doctest directive is not necessary
|
I have fixed the whitespace issues. I tried to be more strict about the textual output whereas I used to relax the testing earlier (i.e. by using the IGNORE_EXCEPTION_DETAIL flag or making use of the whitespace flexibility of the tests), with the intent of making the tests more robust to little changes. |
doc/source/user/quickstart.rst
Outdated
| [ 5, 6, 7, 8, 9], | ||
| [10, 11, 12, 13, 14]]) | ||
| [ 5, 6, 7, 8, 9], | ||
| [10, 11, 12, 13, 14]]) |
There was a problem hiding this comment.
This change looks wrong to me
There was a problem hiding this comment.
I did a lot of copy-paste, tabs got mixed in by mistake. Funnily, it passes pytest and refguide_check. Fix coming.
| [[17, 16, 18, 20, 15], | ||
| [14, 13, 15, 17, 12], | ||
| [13, 12, 14, 16, 11]], | ||
| <BLANKLINE> |
There was a problem hiding this comment.
@mattip, did we delivery choose to avoid using BLANKLINE?
There was a problem hiding this comment.
The recent file absolute_beginners.rst uses BLANKLINE, for instance. But refguide_check.py does not care, it is true. I was led into putting them by pytest.
There was a problem hiding this comment.
We tried to work around <BLANKLINE> but there are places we couldn't avoid it. I don't remember the details. My conclusion when messing with it was that we should move to astropy's pytest-doctestplus rather than enhance refguide-check.
There was a problem hiding this comment.
It seems you must either mash the blocks together without a blank line between them or use the <BLANKLINE> directive to indicate that formatting leaves a blankline there. The first is a bit misleading, I think I prefer the way it is now.
There was a problem hiding this comment.
Should I attempt to resolve the remaining failures:
ERROR: failed checking doc/source/reference/arrays.nditer.rst
failed checking doc/source/user/tutorial-svd.rst
failed checking doc/source/user/c-info.python-as-glue.rst
failed checking doc/source/f2py/getting-started.rst
Or should I test drive the astropy tool?
There was a problem hiding this comment.
I think we should push forward with the current tool. Once we have cleaned up the last failures, we can add the check to CI, then the transition to the new tool can proceed in a controlled way.
eric-wieser
left a comment
There was a problem hiding this comment.
All looks good except the one comment, and a question for Matti
|
Thanks @pdebuyl |
Related to #14970
Fix refguide_check.py test for file doc/source/user/quickstart.rst
Fix printing of arrays.
Add doctest flag +IGNORE_EXCEPTION_DETAIL.
Fix view example with "c.base is a" by declaring "a" without reshaping.
I think that there is no controversial change in this one. The "view" example fails used to fail because a was defined by a reshape and did not "own" its data.