Skip to content

TEST: allow refcheck result to vary, increase discoverability of refcheck option#13096

Merged
tylerjereddy merged 1 commit intonumpy:masterfrom
mattip:doctest-random
Mar 6, 2019
Merged

TEST: allow refcheck result to vary, increase discoverability of refcheck option#13096
tylerjereddy merged 1 commit intonumpy:masterfrom
mattip:doctest-random

Conversation

@mattip
Copy link
Copy Markdown
Member

@mattip mattip commented Mar 5, 2019

Occasionally refcheck tests were failing since the sample mean was not close enough to the desired one. Decrease the probability of failure by increasing the sample size.

Also add doctest to the help for the refguide option to aid discoverability.

@charris
Copy link
Copy Markdown
Member

charris commented Mar 5, 2019

That only decreases the error by a factor of sqrt(10). Could bite the bullet and set the rng seed.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Mar 5, 2019

Agreed, just set the seed so that this problem doesn't occur - our tests should not need to test general statistics!

@mattip
Copy link
Copy Markdown
Member Author

mattip commented Mar 5, 2019

Should we leave it to the doctest to explicitly set the seed, or make it a general feature of refcheck before each new code run?

@charris
Copy link
Copy Markdown
Member

charris commented Mar 5, 2019

Should we leave it to the doctest to explicitly set the seed, or make it a general feature of refcheck before each new code run?

Hmm. If it is in the doctest it would work for cut-and-paste, OTOH, making it a feature of refcheck might be a good insurance policy and allow repeatability. In this case I think the checks for mean and variance are part of the problem, maybe just print the values with an explanatory note that results may vary. If they are close to the expected values, that should be good enough.

@charris
Copy link
Copy Markdown
Member

charris commented Mar 5, 2019

If setting the seed in refcheck would reset the value for every test, that might slow things down. If there is a quarantee of the order in which the tests in each example are performed, it might be better to set the seed in those tests that need it.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Mar 5, 2019

Agreed with @charris that in this case the tests are not that good, and that it is probably more instructure to write: "Verify that the mean is close to 0 and the standard deviation close to 1" and then just print those (with a doctest: +SKIP).

Perhaps that could be the general policy as well: just don't do tests on random data in doctests, and in regular tests be sure to set a seed.

@tylerjereddy
Copy link
Copy Markdown
Contributor

The # may vary directive in refguide is suitable for these scenarios too. It is already present in many of our docstrings.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Mar 5, 2019

Yes, that seems better. I clearly should look more closely at refguide - we should probably start using it in astropy as well...

@rgommers
Copy link
Copy Markdown
Member

rgommers commented Mar 5, 2019

Yes, that seems better. I clearly should look more closely at refguide - we should probably start using it in astropy as well...

good idea. at some point we should bit the bullet and make it a self-contained thing that people can then either depend on or vendor, rather than keep copying it around.

@rgommers
Copy link
Copy Markdown
Member

rgommers commented Mar 5, 2019

Hmm. If it is in the doctest it would work for cut-and-paste, OTOH, making it a feature of refcheck might be a good insurance policy and allow repeatability

If seeds are forgotten, it is probably better just to let the test fail. otherwise the results are stable for us but not for users, which will in the end be more confusing for them

@mattip mattip changed the title TEST: decrease probability of test failure by increasing the sample size TEST: allow refcheck result to vary, increase discoverability of refcheck option Mar 6, 2019
@mattip
Copy link
Copy Markdown
Member Author

mattip commented Mar 6, 2019

Added a # may vary comment.

Copy link
Copy Markdown
Contributor

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

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

This is a simple docstring / refguide-related improvement now so merging, thanks Matti

@tylerjereddy tylerjereddy merged commit cbf3a08 into numpy:master Mar 6, 2019
@mattip mattip deleted the doctest-random branch June 8, 2020 06:58
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.

5 participants