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

Return scalar when accessing zero dimensional array #2718

Open
wants to merge 69 commits into
base: main
Choose a base branch
from

Conversation

brokkoli71
Copy link
Member

@brokkoli71 brokkoli71 commented Jan 15, 2025

0-dimensional arrays are now returning a scalar. Therefore, the return type of __getitem__ changed
to NDArrayOrScalarLike. This change is to make the behavior of 0-dimensional arrays consistent with
numpy scalars.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.rst
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@brokkoli71
Copy link
Member Author

brokkoli71 commented Jan 15, 2025

Do we want to return scalars when accessing zero-dimensional arrays? This would mean that the return value of __getitem__ is no longer NDArrayLike and may make typing more difficult

@brokkoli71 brokkoli71 marked this pull request as draft January 15, 2025 21:43
@dstansby
Copy link
Contributor

To copy what numpy does (see #2713 (comment)), I think we do want to return a scalar.

@github-actions github-actions bot added the needs release notes Automatically applied to PRs which haven't added release notes label Jan 29, 2025
@brokkoli71 brokkoli71 marked this pull request as draft February 12, 2025 10:52
@brokkoli71 brokkoli71 marked this pull request as ready for review February 12, 2025 14:48
@brokkoli71 brokkoli71 requested a review from d-v-b February 12, 2025 14:48
@brokkoli71
Copy link
Member Author

@d-v-b what do you think about NDArrayLikeOrScalar return type for __getitem__? (better ideas for the name of NDArrayLikeOrScalar are also welcome)

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.

Inconsistent () indexing/size behavior from v2->v3
3 participants