Skip to content

DOC: Fix quickstart doc to pass refguide#15703

Merged
mattip merged 9 commits intonumpy:masterfrom
pdebuyl:fix_userguide_quickstart
Mar 5, 2020
Merged

DOC: Fix quickstart doc to pass refguide#15703
mattip merged 9 commits intonumpy:masterfrom
pdebuyl:fix_userguide_quickstart

Conversation

@pdebuyl
Copy link
Contributor

@pdebuyl pdebuyl commented Mar 4, 2020

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.

Fix printing of arrays.
Add doctest flag +IGNORE_EXCEPTION_DETAIL.
Fix view example with "c.base is a" by declaring "a" without reshaping.
@pdebuyl
Copy link
Contributor Author

pdebuyl commented Mar 4, 2020

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?

@eric-wieser
Copy link
Member

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.

Traceback (most recent call last):
File "<stdin>", line 1, in ?
...
IndexError: index (3) out of range (0<=index<=2) in dimension 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message isn't accurate any more - can you update it to be correct?


# not what we want
>>> a[s]
>>> a[s] # doctest: +IGNORE_EXCEPTION_DETAIL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this is not needed if you fix the error message below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is right.

@pdebuyl
Copy link
Contributor Author

pdebuyl commented Mar 4, 2020

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.

Comment on lines 342 to 345
>>> 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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? What error message is refguide expecting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doctest directive is not necessary

@pdebuyl
Copy link
Contributor Author

pdebuyl commented Mar 4, 2020

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.

[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks wrong to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattip, did we delivery choose to avoid using BLANKLINE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@mattip mattip Mar 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good except the one comment, and a question for Matti

@mattip mattip merged commit 459bfb4 into numpy:master Mar 5, 2020
@mattip
Copy link
Member

mattip commented Mar 5, 2020

Thanks @pdebuyl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants