Skip to content

Clean-up indexing adapter classes #10355

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

Merged
merged 27 commits into from
Jul 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bc94c6d
clean-up indexing.PandasIndexingAdapter typing
benbovy May 9, 2025
17ff7e9
streamline PandasIndexingAdapter indexing logic
benbovy May 9, 2025
2b25155
clean-up PandasIndexingAdapter dtype handling
benbovy May 9, 2025
9981078
more clean-up
benbovy May 9, 2025
29098ac
repr: prevent loading lazy variables into memory
benbovy May 26, 2025
5f09354
fix array (index) subsetting
benbovy May 26, 2025
c4a853e
Merge branch 'main' into cleanup-pandas-indexing-adapter
benbovy Jul 4, 2025
0e5154c
treat multi-index and coord-transform variables as lazy
benbovy Jul 4, 2025
4efb135
update whats new
benbovy Jul 4, 2025
ef73a7e
add benchmarks for pandas and xarray RangeIndex
benbovy Jul 7, 2025
28b661a
Merge branch 'main' into cleanup-pandas-indexing-adapter
benbovy Jul 7, 2025
a2ccb7d
fix benchmark numba import error (numpy 2.3)
benbovy Jul 7, 2025
07f6cdb
benchmark: pin numpy in conf + consistent conda env
benbovy Jul 7, 2025
a953b41
pyproject: bump setuptools(-scm)
benbovy Jul 7, 2025
2be275d
ci benchmarks: try fixing package install
benbovy Jul 7, 2025
825cdb1
next try
benbovy Jul 7, 2025
c890a69
next try
benbovy Jul 7, 2025
16fe98b
next try
benbovy Jul 7, 2025
8ae12f7
benchmarks: try disabling no build isolation
benbovy Jul 7, 2025
f40f38c
Revert "benchmarks: try disabling no build isolation"
benbovy Jul 7, 2025
0ecc214
Revert "next try"
benbovy Jul 7, 2025
74e993c
Revert "next try"
benbovy Jul 7, 2025
3420fc9
Revert "next try"
benbovy Jul 7, 2025
97579f5
Revert "ci benchmarks: try fixing package install"
benbovy Jul 7, 2025
86df720
Revert "pyproject: bump setuptools(-scm)"
benbovy Jul 7, 2025
0887a8e
I'm tired of Python packaging
benbovy Jul 7, 2025
8a76b46
Let's fix all this later
benbovy Jul 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
clean-up indexing.PandasIndexingAdapter typing
  • Loading branch information
benbovy committed May 26, 2025
commit bc94c6de33f0972716450e716121f4f33472b9f0
55 changes: 6 additions & 49 deletions xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1846,29 +1846,13 @@ def _prepare_key(self, key: Any | tuple[Any, ...]) -> tuple[Any, ...]:

return key

def _handle_result(
self, result: Any
) -> (
PandasIndexingAdapter
| NumpyIndexingAdapter
| np.ndarray
| np.datetime64
| np.timedelta64
):
def _handle_result(self, result: Any) -> PandasIndexingAdapter | np.ndarray:
if isinstance(result, pd.Index):
return type(self)(result, dtype=self.dtype)
else:
return self._convert_scalar(result)

def _oindex_get(
self, indexer: OuterIndexer
) -> (
PandasIndexingAdapter
| NumpyIndexingAdapter
| np.ndarray
| np.datetime64
| np.timedelta64
):
def _oindex_get(self, indexer: OuterIndexer) -> PandasIndexingAdapter | np.ndarray:
key = self._prepare_key(indexer.tuple)

if getattr(key, "ndim", 0) > 1: # Return np-array if multidimensional
Expand All @@ -1881,13 +1865,7 @@ def _oindex_get(

def _vindex_get(
self, indexer: VectorizedIndexer
) -> (
PandasIndexingAdapter
| NumpyIndexingAdapter
| np.ndarray
| np.datetime64
| np.timedelta64
):
) -> PandasIndexingAdapter | np.ndarray:
_assert_not_chunked_indexer(indexer.tuple)
key = self._prepare_key(indexer.tuple)

Expand All @@ -1901,13 +1879,7 @@ def _vindex_get(

def __getitem__(
self, indexer: ExplicitIndexer
) -> (
PandasIndexingAdapter
| NumpyIndexingAdapter
| np.ndarray
| np.datetime64
| np.timedelta64
):
) -> PandasIndexingAdapter | np.ndarray:
key = self._prepare_key(indexer.tuple)

if getattr(key, "ndim", 0) > 1: # Return np-array if multidimensional
Expand Down Expand Up @@ -1987,29 +1959,15 @@ def _convert_scalar(self, item):
item = item[idx]
return super()._convert_scalar(item)

def _oindex_get(
self, indexer: OuterIndexer
) -> (
PandasIndexingAdapter
| NumpyIndexingAdapter
| np.ndarray
| np.datetime64
| np.timedelta64
):
def _oindex_get(self, indexer: OuterIndexer) -> PandasIndexingAdapter | np.ndarray:
result = super()._oindex_get(indexer)
if isinstance(result, type(self)):
result.level = self.level
return result

def _vindex_get(
self, indexer: VectorizedIndexer
) -> (
PandasIndexingAdapter
| NumpyIndexingAdapter
| np.ndarray
| np.datetime64
| np.timedelta64
):
) -> PandasIndexingAdapter | np.ndarray:
result = super()._vindex_get(indexer)
if isinstance(result, type(self)):
result.level = self.level
Expand All @@ -2019,7 +1977,6 @@ def __getitem__(self, indexer: ExplicitIndexer):
result = super().__getitem__(indexer)
if isinstance(result, type(self)):
result.level = self.level

return result

def __repr__(self) -> str:
Expand Down
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