Skip to content

Commit

Permalink
Merge pull request pandas-dev#40 from manahl/bugfix/list-versions-ret…
Browse files Browse the repository at this point in the history
…urns-deleted

EASY-511 return deleted state in list_versions
  • Loading branch information
eeaston committed Oct 29, 2015
2 parents 965c812 + 089af7d commit 984793a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
10 changes: 6 additions & 4 deletions arctic/store/version_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,16 @@ def list_versions(self, symbol=None, snapshot=None, latest_only=False):
for symbol in symbols:
query['symbol'] = symbol
seen_symbols = set()
for version in self._versions.find(query, projection=['symbol', 'version', 'parent'], sort=[('version', -1)]):
for version in self._versions.find(query, projection=['symbol', 'version', 'parent', 'metadata.deleted'], sort=[('version', -1)]):
if latest_only and version['symbol'] in seen_symbols:
continue
seen_symbols.add(version['symbol'])
meta = version.get('metadata')
versions.append({'symbol': version['symbol'], 'version': version['version'],
# We return offset-aware datetimes in Local Time.
'date': ms_to_datetime(datetime_to_ms(version['_id'].generation_time)),
'snapshots': self._find_snapshots(version.get('parent', []))})
'deleted': meta.get('deleted', False) if meta else False,
# We return offset-aware datetimes in Local Time.
'date': ms_to_datetime(datetime_to_ms(version['_id'].generation_time)),
'snapshots': self._find_snapshots(version.get('parent', []))})
return versions

def _find_snapshots(self, parent_ids):
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/store/test_version_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,26 @@ def test_list_version(library):
assert versions[i]['version'] == x


def test_list_version_deleted(library):
assert len(library.list_versions(symbol)) == 0
library.write(symbol, ts1, prune_previous_version=False)
assert len(library.list_versions(symbol)) == 1
# Snapshot the library so we keep the sentinel version
library.snapshot('xxx', versions={symbol: 1})
library.delete(symbol)
versions = library.list_versions(symbol)
assert len(versions) == 2
assert versions[0]['symbol'] == symbol
assert versions[0]['version'] == 2
assert versions[0]['snapshots'] == []
assert versions[0]['deleted'] == True

assert versions[1]['symbol'] == symbol
assert versions[1]['version'] == 1
assert versions[1]['deleted'] == False
assert versions[1]['snapshots'] == ['xxx']


def test_list_version_latest_only(library):
assert len(list(library.list_versions(symbol))) == 0
dates = [None, None, None]
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/store/test_version_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ def test_list_versions_localTime():
vs._find_snapshots.return_value = 'snap'
date = dt(2013, 4, 1, 9, 0)
vs._versions.find.return_value = [{'_id': bson.ObjectId.from_datetime(date),
'symbol': 's', 'version': 10}]
'symbol': 's', 'version': 10, 'metadata': None}]

version = list(VersionStore.list_versions(vs, "symbol"))[0]
local_date = date.replace(tzinfo=mktz("UTC"))
assert version == {'symbol': version['symbol'], 'version': version['version'],
# We return naive datetimes in 'default' time, which is London for us
'date': local_date,
'snapshots': 'snap'}
'snapshots': 'snap',
'deleted': False}


def test__read_preference__allow_secondary_true():
Expand Down

0 comments on commit 984793a

Please sign in to comment.