Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Remove unused imports, trailing whitespace, fix overridden built in functions, etc
  • Loading branch information
bmoscon committed Jan 3, 2018
1 parent 692d6d9 commit beb6f5a
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 48 deletions.
5 changes: 2 additions & 3 deletions arctic/chunkstore/chunkstore.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import logging
import pymongo
import hashlib
import bson
from collections import defaultdict
from itertools import groupby

import pymongo
from bson.binary import Binary
from pandas import DataFrame, Series
from six.moves import xrange
from itertools import groupby
from pymongo.errors import OperationFailure

from ..decorators import mongo_retry
Expand Down
4 changes: 2 additions & 2 deletions arctic/chunkstore/tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def segment_id_repair(library, symbol=None):
# since the segment is part of the index, we have to clean up first
library._collection.delete_many({SYMBOL: sym, START: segments[0][START]})
# map each segment in the interval to the correct segment
for i in range(len(segments)):
segments[i][SEGMENT] = i
for index, seg in enumerate(segments):
seg[SEGMENT] = index
library._collection.insert_many(segments)
ret.append(sym)

Expand Down
1 change: 0 additions & 1 deletion arctic/fixtures/arctic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import getpass
import logging
import time

import pytest as pytest

Expand Down
1 change: 0 additions & 1 deletion arctic/multi_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
'''
from datetime import datetime
import logging
import types

from pandas import to_datetime as dt

Expand Down
16 changes: 8 additions & 8 deletions arctic/store/_ndarray_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def _promote(type1, type2):

class NdarrayStore(object):
"""Chunked store for arbitrary ndarrays, supporting append.
for the simple example:
dat = np.empty(10)
library.write('test', dat) #version 1
library.append('test', dat) #version 2
version documents:
[
{u'_id': ObjectId('55fa9a7781f12654382e58b8'),
u'symbol': u'test',
Expand All @@ -60,7 +60,7 @@ class NdarrayStore(object):
u'sha': Binary('.........', 0),
u'shape': [-1],
},
{u'_id': ObjectId('55fa9aa981f12654382e58ba'),
u'symbol': u'test',
u'version': 2
Expand All @@ -74,7 +74,7 @@ class NdarrayStore(object):
u'segment_count': 2, #2 segments included in this version
}
]
segment documents:
Expand Down Expand Up @@ -167,7 +167,7 @@ def read(self, arctic_lib, version, symbol, read_preference=None, **kwargs):
def _do_read(self, collection, version, symbol, index_range=None):
'''
index_range is a 2-tuple of integers - a [from, to) range of segments to be read.
Either from or to can be None, indicating no bound.
Either from or to can be None, indicating no bound.
'''
from_index = index_range[0] if index_range else None
to_index = version['up_to']
Expand Down Expand Up @@ -405,7 +405,7 @@ def write(self, arctic_lib, version, symbol, item, previous_version, dtype=None)
version['type'] = self.TYPE
version['up_to'] = len(item)
version['sha'] = self.checksum(item)

if previous_version:
if 'sha' in previous_version \
and self.checksum(item[:previous_version['up_to']]) == previous_version['sha']:
Expand Down Expand Up @@ -488,7 +488,7 @@ def _segment_index(self, new_data, existing_index, start, new_segments):
segments: list of offsets. Each offset is the row index of the
the last row of a particular chunk relative to the start of the _original_ item.
array(new_data) - segments = array(offsets in item)
Returns:
--------
Library specific index metadata to be stored in the version document.
Expand Down
36 changes: 18 additions & 18 deletions arctic/store/bson_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,64 +86,64 @@ def insert_many(self, documents, **kwargs):
self._arctic_lib.check_quota()
return self._collection.insert_many(documents, **kwargs)

def delete_one(self, filter, **kwargs):
def delete_one(self, query_filter, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.delete_one
"""
return self._collection.delete_one(filter, **kwargs)
return self._collection.delete_one(query_filter, **kwargs)

@mongo_retry
def delete_many(self, filter, **kwargs):
def delete_many(self, query_filter, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.delete_many
"""
return self._collection.delete_many(filter, **kwargs)
return self._collection.delete_many(query_filter, **kwargs)

@mongo_retry
def update_one(self, filter, update, **kwargs):
def update_one(self, query_filter, update, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.update_one
"""
self._arctic_lib.check_quota()
return self._collection.update_one(filter, update, **kwargs)
return self._collection.update_one(query_filter, update, **kwargs)

@mongo_retry
def update_many(self, filter, update, **kwargs):
def update_many(self, query_filter, update, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.update_many
"""
self._arctic_lib.check_quota()
return self._collection.update_many(filter, update, **kwargs)
return self._collection.update_many(query_filter, update, **kwargs)

@mongo_retry
def replace_one(self, filter, replacement, **kwargs):
def replace_one(self, query_filter, replacement, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.replace_one
"""
self._arctic_lib.check_quota()
return self._collection.replace_one(filter, replacement, **kwargs)
return self._collection.replace_one(query_filter, replacement, **kwargs)

@mongo_retry
def find_one_and_replace(self, filter, replacement, **kwargs):
def find_one_and_replace(self, query_filter, replacement, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find_one_and_replace
"""
self._arctic_lib.check_quota()
return self._collection.find_one_and_replace(filter, replacement, **kwargs)
return self._collection.find_one_and_replace(query_filter, replacement, **kwargs)

@mongo_retry
def find_one_and_update(self, filter, update, **kwargs):
def find_one_and_update(self, query_filter, update, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find_one_and_update
"""
self._arctic_lib.check_quota()
return self._collection.find_one_and_update(filter, update, **kwargs)
return self._collection.find_one_and_update(query_filter, update, **kwargs)

def find_one_and_delete(self, filter, **kwargs):
def find_one_and_delete(self, query_filter, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find_one_and_delete
"""
return self._collection.find_one_and_delete(filter, **kwargs)
return self._collection.find_one_and_delete(query_filter, **kwargs)

@mongo_retry
def bulk_write(self, requests, **kwargs):
Expand All @@ -157,11 +157,11 @@ def bulk_write(self, requests, **kwargs):
return self._collection.bulk_write(requests, **kwargs)

@mongo_retry
def count(self, filter, **kwargs):
def count(self, query_filter, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.count
"""
return self._collection.count(filter, **kwargs)
return self._collection.count(query_filter, **kwargs)

@mongo_retry
def distinct(self, key, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion arctic/store/version_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..date import mktz, datetime_to_ms, ms_to_datetime
from ..decorators import mongo_retry
from ..exceptions import NoDataFoundException, DuplicateSnapshotException, \
OptimisticLockException, ArcticException
ArcticException
from ..hooks import log_exception
from ._pickle_store import PickleStore
from ._version_store_utils import cleanup
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/chunkstore/test_chunkstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ def test_metadata_invalid(chunkstore_lib):
df = DataFrame(data={'data': np.random.randint(0, 100, size=2)},
index=pd.date_range('2016-01-01', '2016-01-02'))
df.index.name = 'date'
with pytest.raises(Exception) as e:
with pytest.raises(Exception):
chunkstore_lib.write('data', df, chunk_size='M', metadata=df)


Expand Down
6 changes: 3 additions & 3 deletions tests/integration/chunkstore/test_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def test_compression(chunkstore_lib):
"""
Issue 407 - Chunkstore was not removing the 1st segment, with segment id -1
so on an append it would append new chunks with id 0 and 1, and a subsequent read
would still pick up -1 (which should have been removed or overwritten).
Since the -1 segment (which previously indicated a standalone segment) is no
would still pick up -1 (which should have been removed or overwritten).
Since the -1 segment (which previously indicated a standalone segment) is no
longer needed, the special -1 segment id is now removed
"""
def generate_data(date):
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_rewrite(chunkstore_lib):
incorrectly storing and updating metadata. dataframes without an index
have no "index" field in their metadata, so updating existing
metadata does not remove the index field.
Also, metadata was incorrectly being stored. symbol, start, and end
Also, metadata was incorrectly being stored. symbol, start, and end
are the index for the collection, but metadata was being
stored without an index (so it was defaulting to null,null,null)
"""
Expand Down
1 change: 0 additions & 1 deletion tests/integration/scripts/test_list_libraries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from mock import patch, call
import pytest

from arctic.scripts import arctic_list_libraries

Expand Down
4 changes: 0 additions & 4 deletions tests/integration/store/test_ndarray_store_append.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import bson
from datetime import datetime as dt, timedelta as dtd
from mock import patch
import numpy as np
from numpy.testing import assert_equal
from pymongo.server_type import SERVER_TYPE
import pytest

from arctic.store._ndarray_store import NdarrayStore, _APPEND_COUNT
from arctic.store.version_store import register_versioned_storage
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/tickstore/test_ts_delete.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from datetime import datetime as dt
from mock import patch
import numpy as np
from pandas.util.testing import assert_frame_equal
import pytest

from arctic import arctic as m
from arctic.date import DateRange, CLOSED_OPEN, mktz
from arctic.exceptions import OverlappingDataException, \
NoDataFoundException
from arctic.exceptions import NoDataFoundException


def test_delete(tickstore_lib):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/store/test_pickle_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_read_backward_compatibility():
if sys.version_info[0] >= 3:
with pytest.raises(UnicodeDecodeError), open(fname) as fh:
cPickle.load(fh)
else:
else:
with pytest.raises(TypeError), open(fname) as fh:
cPickle.load(fh)

Expand Down

0 comments on commit beb6f5a

Please sign in to comment.