Skip to content

Clean up backend indexing some more #10376

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dcherian
Copy link
Contributor

Harmonizes some internal code paths to make the async work less painful (#10327).

  1. All "decoding arrays" - BoolTypeArray, StackedBytesArray, NativeEndiannessArray - now support lazy indexing. Previously indexing these arrays loaded them to memory.
  2. Our backends now always return LazilyIndexedArray(BackendArray). This was true for all backends except Scipy. Now the Scipy backend does the same.

I'll add comments for the remaining changes

for k, v in self._variables.items():
v = v.copy(deep=True)
res[k] = v
v._data = indexing.LazilyIndexedArray(v._data)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Harmonizes this test backend with all the other backends

@@ -190,7 +190,7 @@ def ds(self):
def open_store_variable(self, name, var):
return Variable(
var.dimensions,
ScipyArrayWrapper(name, self),
indexing.LazilyIndexedArray(ScipyArrayWrapper(name, self)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

harmonized with the other backends

@@ -717,7 +717,7 @@ def from_variables(

# preserve wrapped pd.Index (if any)
# accessing `.data` can load data from disk, so we only access if needed
data = var._data.array if hasattr(var._data, "array") else var.data
data = var._data if isinstance(var._data, PandasIndexingAdapter) else var.data
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benbovy is this right?

Copy link
Member

Choose a reason for hiding this comment

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

It looks right to me. data = var._data.array if isinstance(... would also work but the pandas Index object should be further extracted from the indexing adapter class via safe_cast_to_index.

array = self.array[self.key]

# self.array[self.key] is now a numpy array when
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a nice win and means we have increased internal consistency.

xref #6874 (comment) and #6874 (comment)

@dcherian dcherian marked this pull request as draft May 30, 2025 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants