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 36 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 an instance of ScalarWrapper, which behaves like a scalar
but follow the NDArrayLike interface. This change is to make the behavior of 0-dimensional arrays
consistent with numpy scalars while not breaking the output format of the NDArrayLike interface.

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 ready for review January 29, 2025 17:22
@brokkoli71
Copy link
Member Author

What do you think of the ScalarWrapper for scalars? My motivation was not to break the output format of the NDArrayLike interface. Feedback is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs release notes Automatically applied to PRs which haven't added release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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