Skip to content

Commit

Permalink
Merge pull request #20 from heikomuller/dev-0.2.1
Browse files Browse the repository at this point in the history
Fix bug when adding snapshot from file without primary key (#19)
  • Loading branch information
heikomuller authored Nov 11, 2020
2 parents 3aba0bc + 330cc8c commit 7285ba4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@

* Include wrapper for CSV files
* Commit CSV files directly to a HISTORE archive


### 0.2.1 - 2020-11-11

* Fix bug when adding snapshot from file without primary key (\#19)
2 changes: 1 addition & 1 deletion histore/archive/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ def merge_rows(
arch_row = arch_reader.next()
# Add remaining document rows to the new archive version.
while doc_row is not None:
# Outout an archive row created from the document row.
# Output an archive row created from the document row.
writer.write_document_row(row=doc_row, version=version)
doc_row = doc_reader.next()
8 changes: 7 additions & 1 deletion histore/document/csv/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def next(self):
-------
histore.document.row.DocumentRow
"""
# Return None if the reader is not set (i.e., because the end of the
# file has been reached).
if self.reader is None:
return None
result = self._next_row
try:
rowid, row = next(self.reader)
Expand All @@ -151,9 +155,11 @@ def next(self):
values=values
)
except StopIteration:
# Close the file if the file is reached.
# Close the file if the end is reached. Set the reader to None in
# order to return None when next is called again.
self._next_row = None
self.reader.close()
self.reader = None
# Return the buffered result
return result

Expand Down
2 changes: 1 addition & 1 deletion histore/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# file LICENSE for full license details.

"""Code version information for histore."""
__version__ = '0.2.0'
__version__ = '0.2.1'
19 changes: 17 additions & 2 deletions tests/archive/store/test_persistent_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ def test_persistent_archive(tmpdir):
assert sorted([v.value for v in rows[0].cells[1].values]) == [32, 33]


def test_merge_file_without_pk(tmpdir):
"""Test merging snapshots of the NYC Watershed data into an archive without
using a primary key (issue #19).
"""
archive = PersistentArchive(
basedir=str(tmpdir),
replace=True
)
s = archive.commit(WATERSHED_1)
diff = archive.diff(s.version - 1, s.version)
assert len(diff.schema().insert()) == 10
assert len(diff.rows().insert()) == 1793


@pytest.mark.parametrize(
'doc',
[
Expand All @@ -77,12 +91,13 @@ def test_persistent_archive(tmpdir):
WATERSHED_1
]
)
def test_watershed_archive(doc, tmpdir):
@pytest.mark.parametrize('replace', [True, False])
def test_watershed_archive(doc, replace, tmpdir):
"""Test merging snapshots of the NYC Watershed data into an archive."""
archive = PersistentArchive(
basedir=str(tmpdir),
primary_key=['Site', 'Date'],
replace=False
replace=replace
)
s = archive.commit(doc)
diff = archive.diff(s.version - 1, s.version)
Expand Down

0 comments on commit 7285ba4

Please sign in to comment.