Skip to content

Commit

Permalink
Allow reading in append mode.
Browse files Browse the repository at this point in the history
Fix #18
  • Loading branch information
Christoph Paulik committed Aug 21, 2017
1 parent 6b8f3b0 commit a5d43d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

Version 0.3.15
==============

- Allow reading of data in append mode.

Version 0.3.14
==============

Expand Down
4 changes: 2 additions & 2 deletions pygeobase/io_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def _read_gp(self, gp, **kwargs):
data : numpy.ndarray
Data set or None in case of an error.
"""
if self.mode in ['w', 'a']:
if self.mode in ['w']:
raise IOError("File is not open in read mode")

data = None
Expand Down Expand Up @@ -647,7 +647,7 @@ def _read_gp(self, gp, **kwargs):
data : object
pygeobase.object_base.TS object
"""
if self.mode in ['w', 'a']:
if self.mode in ['w']:
raise IOError("File is not open in read mode")

data = None
Expand Down
16 changes: 14 additions & 2 deletions tests/test_io_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def read_ts(self, gpi, factor=1):
raise IOError("GPI does not exist")
return gpi * factor

def write(self, gpi, data):
def write(self, gpi, data, **kwargs):
return None

def write_ts(self, gpi, data):
def write_ts(self, gpi, data, **kwargs):
return None

def close(self):
Expand All @@ -82,6 +82,18 @@ def test_gridded_ts_base_iter_ts():
assert gpi == gpi_should.pop(0)


def test_gridded_ts_base_read_append():
"""
Test reading in append mode in GriddedTs. Should be allowed.
"""
grid = grids.CellGrid(np.array([1, 2, 3, 4]), np.array([1, 2, 3, 4]),
np.array([4, 4, 2, 1]), gpis=np.array([1, 2, 3, 4]))

ds = GriddedTsBase("", grid, TestDataset, mode='a')
# during iteration the gpis are traversed based on cells for a cell grid
assert ds.read(1) == 1


def test_gridded_ts_base_iter_gp_IOError_None_yield():
"""
Test iteration over time series in GriddedTsBase. Should yield None if IOError is raised.
Expand Down

0 comments on commit a5d43d0

Please sign in to comment.