Skip to content

Commit

Permalink
fix #14 by excepting also IndexError
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Paulik committed Apr 30, 2015
1 parent c774615 commit 9a1bd99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# v0.x #
- added support for saving more subsets and loading a certain one in/from a netcdf grid file
- fix #15 by setting correct shape for derived cell grids
- fix issue #14 of gpi2rowcol input types

# v0.1 #
- Initial version pulled out of pytesmo
Expand Down
2 changes: 1 addition & 1 deletion pygeogrids/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def gpi2rowcol(self, gpi):
try:
gpi[0]
iterable = True
except TypeError:
except (TypeError, IndexError):
iterable = False
gpi = np.atleast_1d(gpi)
if len(self.shape) == 2:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ def test_gpi2rowcol(self):
assert row == row_should
assert column == column_should

def test_gpi2rowcol_np_int(self):
"""
test if gpi to row column lookup works correctly
"""
gpi = np.array([200])[0]
row_should = 1
column_should = 200 - 144
row, column = self.grid.gpi2rowcol(gpi)
assert row == row_should
assert column == column_should

def test_gpi2rowcol_iterable(self):
"""
test if gpi to row column lookup works correctly
Expand Down

0 comments on commit 9a1bd99

Please sign in to comment.