Skip to content

Add async oindex and vindex methods to AsyncArray #3083

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

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

Conversation

TomNicholas
Copy link
Member

@TomNicholas TomNicholas commented May 23, 2025

Array has .oindex and .vindex methods, but AsyncArray has no equivalent. This PR adds them. It only adds the get methods, not the set methods, which I thought could be deferred to a follow-up PR.

I want it for pydata/xarray#10327 (comment)

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)

@github-actions github-actions bot added the needs release notes Automatically applied to PRs which haven't added release notes label May 23, 2025
TomNicholas added a commit to TomNicholas/xarray that referenced this pull request May 23, 2025
@TomNicholas TomNicholas changed the title Add async oindex method to AsyncArray Add async oindex and vindex methods to AsyncArray May 29, 2025
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

Attention: Patch coverage is 50.87719% with 28 lines in your changes missing coverage. Please review.

Project coverage is 59.60%. Comparing base (a27d4d6) to head (c0026e9).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/zarr/core/indexing.py 46.42% 15 Missing ⚠️
src/zarr/core/array.py 54.16% 11 Missing ⚠️
src/zarr/core/common.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3083      +/-   ##
==========================================
- Coverage   59.65%   59.60%   -0.06%     
==========================================
  Files          78       78              
  Lines        8690     8741      +51     
==========================================
+ Hits         5184     5210      +26     
- Misses       3506     3531      +25     
Files with missing lines Coverage Δ
src/zarr/core/chunk_grids.py 45.58% <ø> (+0.66%) ⬆️
src/zarr/core/common.py 39.13% <60.00%> (+1.19%) ⬆️
src/zarr/core/array.py 68.59% <54.16%> (-0.44%) ⬇️
src/zarr/core/indexing.py 68.40% <46.42%> (-0.82%) ⬇️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TomNicholas
Copy link
Member Author

TomNicholas commented Jul 22, 2025

@dcherian suggested making the sync oindex and vindex getitem methods call the new async versions.

EDIT: I think this is already the case?

@github-actions github-actions bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Jul 23, 2025
if is_coordinate_selection(new_selection, self.array.shape):
return await self.array.get_coordinate_selection(new_selection, fields=fields)
elif is_mask_selection(new_selection, self.array.shape):
return await self.array.get_mask_selection(new_selection, fields=fields)
Copy link
Member Author

@TomNicholas TomNicholas Jul 23, 2025

Choose a reason for hiding this comment

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

I had to add .get_mask_selection to AsyncArray to cover this codepath. But I only realised I needed to thanks to mypy. This means that this codepath is

  • not needed for me right now (I think)
  • definitely not covered by the property tests

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I haven't added mask indexing to the property test suite

Comment on lines +1611 to +1612
@property
def oindex(self) -> AsyncOIndex[T_ArrayMetadata]:
Copy link
Member Author

Choose a reason for hiding this comment

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

I chose this API to try to follow this pattern:

  • Array.__getitem__ (exists)
  • Array.oindex.__getitem__ (exists)
  • Array.vindex.__getitem__ (exists)
  • AsyncArray.getitem (exists)
  • AsyncArray.oindex.getitem (new)
  • AsyncArray.vindex.getitem (new)

because python doesn't let you make an async version of the __getitem__ magic method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we update the sync versions to use sync(self._async_array.oindex.getitem) instead of going to _get_selection directly? That will get us some test coverage

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I also be adding tests to test_indexing.py?

@@ -1425,6 +1427,56 @@ async def getitem(
)
return await self._get_selection(indexer, prototype=prototype)

async def get_orthogonal_selection(
Copy link
Member Author

Choose a reason for hiding this comment

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

get_basic_selection also doesn't exist on AsyncArray - should I add that too?

@pytest.mark.asyncio
@given(data=st.data())
@pytest.mark.filterwarnings("ignore::zarr.core.dtype.common.UnstableSpecificationWarning")
async def test_oindex_async(data: st.DataObject) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just merge these with the sync versions of these tests. we can test both async and sync within one async test function

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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy