8000 DEP: Deprecate random_integers by gfyoung · Pull Request #6931 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DEP: Deprecate random_integers #6931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2016
Merged

DEP: Deprecate random_integers #6931

merged 1 commit into from
Jan 10, 2016

Conversation

gfyoung
Copy link
Contributor
@gfyoung gfyoung commented Jan 3, 2016

Follow-up to the discussion #6910 in which to deprecate np.random.random_integers in favor of np.random.randint.

@charris
Copy link
Member
charris commented Jan 3, 2016

Should raise this on the list. Would be good if @rkern weighs in there.

@gfyoung
Copy link
Contributor Author
gfyoung commented Jan 4, 2016

Sent out email here

@homu
Copy link
Contributor
homu commented Jan 4, 2016

☔ The latest upstream changes (presumably #6936) made this pull request unmergeable. Please resolve the merge conflicts.

@gfyoung
Copy link
Contributor Author
gfyoung commented Jan 9, 2016

Is this good to merge? Travis and Appevoyor are both happy, the branch no longer has any merge conflicts, and judging from the email, @rkern has given the green light.

@@ -255,6 +255,18 @@ def test_random_integers_max_int(self):
desired = np.iinfo('l').max
np.testing.assert_equal(actual, desired)

def test_random_integers_deprecated(self):
Copy link
Member

Choose a reason for hiding this comment

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

Because Deprecation warnings are error for development testing and only raised once from a giving location by default, some care needs to be taken here. There is a _DeprecationTestCase in numpy/core/tests/test_deprecations.py that can be used as a base class and perhaps should be moved into numpy.testing, another, somewhat simpler option is

        with warnings.catch_warnings():
            warnings.simplefilter("error", DeprecationWarning)
            assert_raises(DeprecationWarning, ...)

@seberg Thoughts about moving the _DeprecationTestCase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@charris : Could you clarify your comment? There seems to be a mixture of suggestions for this actual PR and suggestions of a greater infrastructural change. Should I move my test into test_deprecations.py as a derived class of _DeprecationTestCase?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, one is a more invasive change than the other. Quick and dirty is the simple option, the move is somewhat more complicated, but maybe provides functionality other spots would like. The idea isn't to move these tests, but rather put _DeprecationTestCase, without the underscore, someplace where you can get at it. Let's wait a bit and see if we get a second opinion.

Copy link
Member

Choose a reason for hiding this comment

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

I'm -0 on adding _DeprecationTestCase to the public API, because it feels a bit underbaked (assert_deprecated's calling convention is super complicated!), so probably we shouldn't set it in stone as-is.

No objections to refactoring our test suite to have more useful internal tools though. Or maybe assert_warns should be clever enough to set up the warning context properly, if it isn't already.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like quick and dirty for 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.

@charris : "quick and dirty" = move test into test_deprecations.py or that with warnings.catch_warnings() block? Both seem to fit the criterion.

Copy link
Member

Choose a reason for hiding this comment

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

Q&D would be least work, e.g., with the catch_warnings environment.

10000

Copy link
Member

Choose a reason for hiding this comment

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

We have this new thing that clears the warning registry? It might go far enough. It is definetely half backed, it was backed by me getting desperate with avoid warning registry corruption.

If you do an assert_warns with "always" in the catch_warnings context, and then an assert_raises when putting DeprecationWarning to "error" you have it I think. I think we also have some new stuff (forgot where), which attempts to clear the warning registry.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, clearing the registry is a good safety measure to ensure that the warning is alway enabled despite previous errors/bad code.

Copy link
Member

Choose a reason for hiding this comment

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

Only that you have to know where the error originates from to do that, which makes it a bit annoying. Actually, did we ever consider setting the warning to "always" for all warnings in the tests? That could decrease the probability of running in those kind of issues.... Next time I will run into it, which as far as I see is as soon as I want to waste more time on oindex related deprecations, hehe.

@gfyoung
Copy link
Contributor Author
gfyoung commented Jan 10, 2016

@charris @seberg : Modified the tests as requested, and Travis + Appveyor are happy still. Should be good to merge then if there is nothing else.

In accordance with the Python C API, which gives preference to the half-open
interval over the closed one, ```np.random.random_integers``` is being
deprecated in favor of calling ```np.random.randint``` with the arguments
appropriately adjusted. Work has already been done to begin phasing out
Copy link
Member

Choose a reason for hiding this comment

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

Should probably mention that random_integers will not be removed anytime soon. Also, instead of saying that random_integers lacks the new features, point out that randint has new features not available in random_integers. Make it an endorsement of randint, not a put down of random_integers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

charris added a commit that referenced this pull request Jan 10, 2016
@charris charris merged commit 3a9c90c into numpy:master Jan 10, 2016
@charris
Copy link
Member
charris commented Jan 10, 2016

Thanks @gfyoung .

@anntzer
Copy link
Contributor
anntzer commented Jul 29, 2016

It may also be worth removing references to random_integers in other functions's See also sections? In particular randint's docstring contains this rather confusing remark about random_integers:

        See Also
        --------
        random.random_integers : similar to `randint`, only for the closed
            interval [`low`, `high`], and 1 is the lowest value if `high` is
            omitted. In particular, this other one is the one to use to generate
            uniformly distributed discrete non-integers.

What does this second sentence even mean?

@gfyoung
Copy link
Contributor Author
gfyoung commented Jul 29, 2016

Not sure at the moment...you can submit a PR for I guess to clarify the meaning.

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.

6 participants
0