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

Enable explicit use of key tuples (instead of *Indexer objects) in indexing adapters and explicitly indexed arrays #8870

Conversation

andersy005
Copy link
Member

@andersy005 andersy005 changed the title Enable explicit use of key tuples (instead of *Indexer objects) for indexing in indexing adapters and explicitly indexed arrays Enable explicit use of key tuples (instead of *Indexer objects) in indexing adapters and explicitly indexed arrays Mar 23, 2024
xarray/coding/strings.py Outdated Show resolved Hide resolved
@andersy005 andersy005 changed the base branch from main to backend-indexing April 10, 2024 00:07
@andersy005 andersy005 marked this pull request as ready for review April 30, 2024 12:10
@andersy005 andersy005 mentioned this pull request Apr 30, 2024
20 tasks
xarray/coding/strings.py Outdated Show resolved Hide resolved
xarray/core/indexing.py Outdated Show resolved Hide resolved
@@ -5811,7 +5811,7 @@ def _getitem(self, key):

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
la.vindex[indexer].get_duck_array()
la.vindex[indexer.tuple].get_duck_array()
Copy link
Contributor

@dcherian dcherian Apr 30, 2024

Choose a reason for hiding this comment

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

Suggested change
la.vindex[indexer.tuple].get_duck_array()
la[indexer].get_duck_array()

This is where we check for backcompat warnings in custom backends. Is the warning being raised when we pass .tuple to .vindex? It should not be..

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 intend to look into this later today

xarray/core/indexing.py Outdated Show resolved Hide resolved
andersy005 and others added 2 commits April 30, 2024 14:13
Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
key = BasicIndexer(
indexer.tuple if isinstance(indexer, ExplicitIndexer) else indexer
)
return type(self)(self.array, self._updated_key(key))
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's fix self._updated_key to not need Indexer objects

Copy link
Member Author

Choose a reason for hiding this comment

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

added some initial updates with support for raw tuples as input. however, there's still use of indexer objects within the method itself. my attempts at completely removing indexer objects resulted in plenty of issues that i wasn't ready to address :). will look into this later today as well

xarray/coding/strings.py Outdated Show resolved Hide resolved
@dcherian dcherian merged commit 245c3db into pydata:backend-indexing May 3, 2024
23 checks passed
@dcherian
Copy link
Contributor

dcherian commented May 3, 2024

Very nice work, Anderson!

We can address the backend warnings in the next PR

andersy005 added a commit that referenced this pull request May 10, 2024
…dexing adapters and explicitly indexed arrays (#8870)

* pass key tuple to indexing adapters and explicitly indexed arrays

* update indexing in StackedBytesArray

* Update indexing in StackedBytesArray

* Add _IndexerKey type to _typing.py

* Update indexing in StackedBytesArray

* use tuple indexing in test_backend_array_deprecation_warning

* Add support for CompatIndexedTuple in explicit indexing adapter

This commit updates the `explicit_indexing_adapter` function to accept both
`ExplicitIndexer` and the new `CompatIndexedTuple`. The `CompatIndexedTuple` is
designed to facilitate the transition towards using raw tuples by carrying
additional metadata about the indexing type (basic, vectorized, or outer).

* remove unused code

* type hint fixes

* fix docstrings

* fix tests

* fix docstrings

* Apply suggestions from code review

Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>

* update docstrings and pass tuples directly

* Some test cleanup

* update docstring

* use `BasicIndexer` instead of `CompatIndexedTuple`

* support explicit indexing with tuples

* fix mypy errors

* remove unused IndexerMaker

* Update LazilyIndexedArray._updated_key to support explicit indexing with tuples

---------

Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
Co-authored-by: Deepak Cherian <deepak@cherian.net>
andersy005 added a commit to hmaarrfk/xarray that referenced this pull request May 10, 2024
* backend-indexing:
  Trigger CI only if code files are modified. (pydata#9006)
  Enable explicit use of key tuples (instead of *Indexer objects) in indexing adapters and explicitly indexed arrays (pydata#8870)
  add `.oindex` and `.vindex` to `BackendArray` (pydata#8885)
  temporary enable CI triggers on feature branch
  Avoid auto creation of indexes in concat (pydata#8872)
  Fix benchmark CI (pydata#9013)
  Avoid extra read from disk when creating Pandas Index. (pydata#8893)
  Add a benchmark to monitor performance for large dataset indexing (pydata#9012)
  Zarr: Optimize `region="auto"` detection (pydata#8997)
  Trigger CI only if code files are modified. (pydata#9006)
  Fix for ruff 0.4.3 (pydata#9007)
  Port negative frequency fix for `pandas.date_range` to `cftime_range` (pydata#8999)
  Bump codecov/codecov-action from 4.3.0 to 4.3.1 in the actions group (pydata#9004)
  Speed up localize (pydata#8536)
  Simplify fast path (pydata#9001)
  Add argument check_dims to assert_allclose to allow transposed inputs (pydata#5733) (pydata#8991)
  Fix syntax error in test related to cupy (pydata#9000)
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.

None yet

3 participants