Skip to content

Commit

Permalink
Fix #28 by resetting cell number only when the file exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Paulik committed Feb 26, 2016
1 parent c89ba98 commit 4b5b70b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pygeobase/io_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ def _open(self, gp):
if self.mode == 'r':
if self.previous_cell != cell:
self.close()
self.previous_cell = cell

try:
self.fid = self.ioclass(filename, mode=self.mode,
**self.ioclass_kws)
self.previous_cell = cell
except IOError as e:
success = False
self.fid = None
Expand All @@ -369,10 +369,10 @@ def _open(self, gp):
if self.previous_cell != cell:
self.flush()
self.close()
self.previous_cell = cell
try:
self.fid = self.ioclass(filename, mode=self.mode,
**self.ioclass_kws)
self.previous_cell = cell
except IOError as e:
success = False
self.fid = None
Expand Down
5 changes: 3 additions & 2 deletions tests/test_io_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TestDataset(object):
def __init__(self, filename, mode='r'):
self.filename = filename
self.mode = mode
open(filename, mode)

def read(self, gpi):
return None
Expand All @@ -32,10 +33,10 @@ def flush(self):
def test_gridded_ts_base_iter_ts():
"""Test iteration over time series in GriddedTsBase."""
grid = grids.CellGrid(np.array([1, 2, 3, 4]), np.array([1, 2, 3, 4]),
np.array([4, 3, 2, 1]), gpis=np.array([1, 2, 3, 4]))
np.array([4, 4, 2, 1]), gpis=np.array([1, 2, 3, 4]))

ds = GriddedTsBase("", grid, TestDataset)
# during iteration the gpis are traversed based on cells for a cell grid
gpi_should = [4, 3, 2, 1]
gpi_should = [4, 3, 1, 2]
for ts, gpi in ds.iter_ts():
assert gpi == gpi_should.pop(0)

0 comments on commit 4b5b70b

Please sign in to comment.