From 5b4d160d9a714c2cc83ff5788e2d73af92129713 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Mon, 8 Oct 2018 11:17:01 -0700 Subject: [PATCH] Fix indexing error for data loaded with open_rasterio (#2456) xref GH2454 --- doc/whats-new.rst | 6 +++++- xarray/backends/rasterio_.py | 2 +- xarray/tests/test_backends.py | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 85e9f2313d6..7cdb1685f5f 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -76,6 +76,10 @@ Bug fixes By `Deepak Cherian `_. +- Fix a bug that caused some indexing operations on arrays opened with + ``open_rasterio`` to error (:issue:`2454`). + By `Stephan Hoyer `_. + .. _whats-new.0.10.9: v0.10.9 (21 September 2018) @@ -86,7 +90,7 @@ This minor release contains a number of backwards compatible enhancements. Announcements of note: - Xarray is now a NumFOCUS fiscally sponsored project! Read - `the anouncment `_ + `the anouncement `_ for more details. - We have a new :doc:`roadmap` that outlines our future development plans. diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index 9cd5a889abc..44cca9aaaf8 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -95,7 +95,7 @@ def _get_indexer(self, key): if isinstance(key[1], np.ndarray) and isinstance(key[2], np.ndarray): # do outer-style indexing - np_inds[1:] = np.ix_(*np_inds[1:]) + np_inds[-2:] = np.ix_(*np_inds[-2:]) return band_key, tuple(window), tuple(squeeze_axis), tuple(np_inds) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index a2e1cb4c0fa..0d97ed70fa3 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -2925,6 +2925,10 @@ def test_indexing(self): assert_allclose(expected.isel(**ind), actual.isel(**ind)) assert not actual.variable._in_memory + ind = {'band': 0, 'x': np.array([0, 0]), 'y': np.array([1, 1, 1])} + assert_allclose(expected.isel(**ind), actual.isel(**ind)) + assert not actual.variable._in_memory + # minus-stepped slice ind = {'band': np.array([2, 1, 0]), 'x': slice(-1, None, -1), 'y': 0}