Skip to content

DOC, TST Update doctests ref guide#15519

Closed
pdebuyl wants to merge 7 commits intonumpy:masterfrom
pdebuyl:update_doctests_ref_guide
Closed

DOC, TST Update doctests ref guide#15519
pdebuyl wants to merge 7 commits intonumpy:masterfrom
pdebuyl:update_doctests_ref_guide

Conversation

@pdebuyl
Copy link
Contributor

@pdebuyl pdebuyl commented Feb 5, 2020

part of #14970

Mostly "mechanical" changes following the changes of representation, the print function, or missing definitions.

Remove the timezone in the output, which is deprecated since 1.11.

Skip the output showing deliberately the old and deprecated version.
Fix missing np prefix.

Use print function instead of the statement.

Add seed to make output repeatable.
Print statements, changes in the array repr.
@pdebuyl pdebuyl requested a review from eric-wieser February 5, 2020 20:47
Comment on lines 220 to +228
... print("%d <%d>" % (it[0], it.index), end=' ')
... it.iternext()
...
0 <0> 1 <2> 2 <4> 3 <1> 4 <3> 5 <5>
0 <0> True
1 <2> True
2 <4> True
3 <1> True
4 <3> True
5 <5> False
Copy link
Member

@eric-wieser eric-wieser Feb 5, 2020

Choose a reason for hiding this comment

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

This doesn't look right - what is printing the booleans?

(edit: xref #15519 (comment))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a IPython terminal, I obtain the "old" result. When running the refguide_check.py tool the output is as in the commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a "plain" Python REPL, the output contains the booleans. All lines that return a value seem to appear. This type of detail is hard to find in the Python docs, it seems that it is "assumed to be known"...

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.

Mostly looks good. I'd like:

  • @mattip's feedback on the use of doctest markers here
  • To understand the True / False printouts in the iteration examples

@@ -220,20 +220,37 @@ produce identical results to the ones in the previous section.
... print("%d <%d>" % (it[0], it.index), end=' ')
... it.iternext()
Copy link
Member

Choose a reason for hiding this comment

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

It's nasty, but this would make the output go away:

Suggested change
... it.iternext()
... it.iternext()
... None # needed to make the docs build properly :(

Copy link
Member

Choose a reason for hiding this comment

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

Why not v = it.iternext()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, the output that I put in the PR corresponds to the REPL output, that differs from the IPython output. It is a matter of choice between the two.

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 could make both the repl and ipython have the same output if we change line 221 to be v = it.iternext() (and line 233 too)

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 agree. However, it remains hacky: the example is modified for the purpose of a clean doctest but the modification does not reflect a programming necessity or a good practice. That being said, you are in a much better position to make the choice for this matter of style, let me know your decision.

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 it is easier to hide this detail in an unused value than to try to explain why the loop is printing booleans. Good practice would be to use the for loop anyway, I am not a big fan of looping over an iterator with while.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps is_not_finished = ... instead?

Copy link
Member

Choose a reason for hiding this comment

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

, I am not a big fan of looping over an iterator with while.

Even that would be a better example, since next is a lot more useful than our iternext.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, for this PR, we keep the while and I add is_not_finished = ?

Copy link
Member

Choose a reason for hiding this comment

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

yes please

@mattip
Copy link
Member

mattip commented Feb 6, 2020

Does doc/source/reference/arrays.datetime.rst pass cleanly for you? When I run it (after python -m pip install . on latest HEAD and a python 3.6 virtualenv), I see problems with DeprecationWarnings. It seems to be an issue with capturing the warnings when running the doctest. I think it would be better to leave that file out for this PR.

@pdebuyl
Copy link
Contributor Author

pdebuyl commented Feb 6, 2020

Does doc/source/reference/arrays.datetime.rst pass cleanly for you? When I run it (after python -m pip install . on latest HEAD and a python 3.6 virtualenv), I see problems with DeprecationWarnings. It seems to be an issue with capturing the warnings when running the doctest. I think it would be better to leave that file out for this PR.

I also have the warning issue. The PR does not fix all errors, see #14970 (comment)

Regarding the warning, it seems that the doctest runner at

def _run_doctests(tests, full_name, verbose, doctest_warnings):
tries to capture warnings but fails. So, in principle, this should work.

@pdebuyl
Copy link
Contributor Author

pdebuyl commented Feb 6, 2020

PS: how do you run pep8 on the rst files?

@mattip
Copy link
Member

mattip commented Feb 6, 2020

So, in principle, this should work.

Right, so it failing to work is a separate issue. It would be much easier to review your changes if I could (1) run the tests on master, see that they fail, (2) run them on your branch see that they pass, (3) review the changes for anything that looks off. But since (2) fails it means I have to think harder about whether the changes are correct, which is why I would prefer putting off the changes on that file until my preferred workflow is possible.

@mattip
Copy link
Member

mattip commented Feb 6, 2020

PS: how do you run pep8 on the rst files?

Another reason to move to astropy's solution: we could file an issue there and maybe someone would add support :)

@pdebuyl
Copy link
Contributor Author

pdebuyl commented Feb 6, 2020

@mattip I created a separate PR #15532 where all files commited pass the tests. I'll get back to the remaining failing files in the reference guide next week.

@pdebuyl
Copy link
Contributor Author

pdebuyl commented Feb 7, 2020

I close following the merge of #15532 and will get back to it next week.

Should we discuss the strategy for doctesting the guide? At https://github.com/scipy-lectures/scipy-lecture-notes we run pytest on all rst files for instance. I see that astropy also developed a tool, I will give it a look.

@pdebuyl pdebuyl closed this Feb 7, 2020
@eric-wieser
Copy link
Member

Are there parts of this that didn't make it into #15532? It might be useful to reopen and rebase this, so we can see what's still to handle - even if we consider it in a WIP state.

@pdebuyl
Copy link
Contributor Author

pdebuyl commented Feb 7, 2020

For the files arrays.nditer.rst and arrays.datetime.rst this PR decreased the number of errors but did not suppress all of them.

For arrays.datetime.rst: the only remaining problem is that the test runner did not output the warning.

For arrays.nditer.rst there was the while loop output issue but there remained many other errors that I did not investigate yet.

@eric-wieser eric-wieser reopened this Feb 7, 2020
@eric-wieser eric-wieser changed the base branch from master to maintenance/1.18.x February 7, 2020 14:29
@eric-wieser eric-wieser changed the base branch from maintenance/1.18.x to master February 7, 2020 14:29
@eric-wieser
Copy link
Member

Was hoping that would recompute the diff, but it doesn't seem to have

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants