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 cec295d commit 9c202d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.x #
- added support for saving more subsets and loading a certain one in/from a netcdf grid file
- fix issue #14 of gpi2rowcol input types

# v0.1 #
- Initial version pulled out of pytesmo
- added support for iterables like lists and numpy arrays to functions like
Expand All @@ -7,5 +11,3 @@ information from a grid. see issue #3 and #4
- comparison of grids is no longer using exact float comparison, see issue #9
- added documentation and examples for working with the grid objects, see issue #1

# #
- added support for saving more subsets and loading a certain one in/from a netcdf grid file
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 9c202d0

Please sign in to comment.