Skip to content
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

Refactor extra.numpy.basic_indices() handling of max_dims when allow_newaxis=False #3091

Closed
2 tasks
Zac-HD opened this issue Sep 10, 2021 · 3 comments
Closed
2 tasks
Labels
internals Stuff that only Hypothesis devs should ever see legibility make errors helpful and Hypothesis grokable

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Sep 10, 2021

Via #3065 (comment), basic_indices() is doing more work than it needs to when allow_newaxis=False - and that's particularly salient because the array_api extra doesn't have newaxis at all. So the internals part:

  • When allow_newaxis=False, max_dims should be set to len(shape), and
  • We can therefore move it to _array_helpers.py and refactor the array_api extra to use this too

This also suggests a constraint on the arguments that we're not currently enforcing for the Numpy extra:

if max_dims > len(shape) and not allow_newaxis:
    note_deprecation(..., since="RELEASEDAY", has_codemod=False)
    # Becomes `raise InvalidArgument(...)` in the next major version
@Zac-HD Zac-HD added legibility make errors helpful and Hypothesis grokable internals Stuff that only Hypothesis devs should ever see labels Sep 10, 2021
@honno
Copy link
Member

honno commented Sep 11, 2021

Happy to do this—will make a PR next week.

For reference this was the deprecation notice I had written before. I think it covers the right things, I just need to iterate.

>>> nps.basic_indices((3, 3, 3), max_dims=5).example()
HypothesisDeprecationWarning: max_dims=5 and allow_newaxis=False, so we cannot generate indices that would produce arrays with dimensions greater than len(shape)=3 i.e. the dimensions of the indexed array. In the next release, max_dims would default to the the dimensions of shape=(3, 3, 3) when allow_newaxis=False, and passing max_dims greater than len(shape) will raise an error.

@Zac-HD
Copy link
Member Author

Zac-HD commented Sep 11, 2021

How about f"max_dims={max_dims} is larger than len(shape)={len(shape)}, but allow_newaxis=False makes it impossible for an indexing operation to add dimensions."? Trying to mention all the relevant arguments and their relationship early, and then provide a short explanation afterwards.

@Zac-HD
Copy link
Member Author

Zac-HD commented Sep 15, 2021

Closed by #3098.

@Zac-HD Zac-HD closed this as completed Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals Stuff that only Hypothesis devs should ever see legibility make errors helpful and Hypothesis grokable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants