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

Fix isel performance regression #3319

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,16 @@ def setup(self, key):
requires_dask()
super().setup(key)
self.ds = self.ds.chunk({"x": 100, "y": 50, "t": 50})


class BooleanIndexing:
# https://github.com/pydata/xarray/issues/2227
def setup(self):
self.ds = xr.Dataset(
{"a": ("time", np.arange(10_000_000))},
coords={"time": np.arange(10_000_000)},
)
self.time_filter = self.ds.time > 50_000

def time_indexing(self):
self.ds.isel(time=self.time_filter)
12 changes: 6 additions & 6 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,7 @@ def _validate_indexers(
elif isinstance(v, Dataset):
raise TypeError("cannot use a Dataset as an indexer")
elif isinstance(v, Sequence) and len(v) == 0:
v = IndexVariable((k,), np.zeros((0,), dtype="int64"))
v = Variable((k,), np.zeros((0,), dtype="int64"))
else:
v = np.asarray(v)

Expand All @@ -1794,16 +1794,13 @@ def _validate_indexers(
if v.ndim == 0:
v = Variable((), v)
elif v.ndim == 1:
v = IndexVariable((k,), v)
v = Variable((k,), v)
else:
raise IndexError(
"Unlabeled multi-dimensional array cannot be "
"used for indexing: {}".format(k)
)

if v.ndim == 1:
v = v.to_index_variable()

indexers_list.append((k, v))

return indexers_list
Expand Down Expand Up @@ -2366,7 +2363,10 @@ def interp(
if kwargs is None:
kwargs = {}
coords = either_dict_or_kwargs(coords, coords_kwargs, "interp")
indexers = OrderedDict(self._validate_indexers(coords))
indexers = OrderedDict(
(k, v.to_index_variable() if isinstance(v, Variable) and v.ndim == 1 else v)
for k, v in self._validate_indexers(coords)
)

obj = self if assume_sorted else self.sortby([k for k in coords])

Expand Down