Skip to content

Commit 02d0e7d

Browse files
authored
Merge pull request pandas-dev#676 from shashank88/small_fixes
Multiple small formatting changes and enabling pycodestyle in ci
2 parents d443bbf + a0b0673 commit 02d0e7d

25 files changed

+187
-165
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ python:
88
services:
99
- mongodb
1010

11+
before_install:
12+
- pip install pycodestyle
1113
install:
1214
- mongo --version
1315
- pip install --upgrade pip
@@ -31,3 +33,5 @@ install:
3133
script:
3234
- pip freeze
3335
- python setup.py test --pytest-args=-v
36+
# Skipped codes in setup.cfg. Tests not checked for now.
37+
- pycodestyle arctic

arctic/_compression.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
except ImportError as e:
88
from lz4 import compress as lz4_compress, compressHC as lz4_compressHC, decompress as lz4_decompress
99

10+
# ENABLE_PARALLEL mutated in global_scope. Do not remove.
1011
from ._config import ENABLE_PARALLEL, LZ4_HIGH_COMPRESSION, LZ4_WORKERS, LZ4_N_PARALLEL, LZ4_MINSZ_PARALLEL, \
11-
BENCHMARK_MODE
12+
BENCHMARK_MODE # noqa # pylint: disable=unused-import
1213

1314
logger = logging.getLogger(__name__)
1415

@@ -78,8 +79,10 @@ def compress_array(str_list, withHC=LZ4_HIGH_COMPRESSION):
7879

7980
do_compress = lz4_compressHC if withHC else lz4_compress
8081

81-
use_parallel = ENABLE_PARALLEL and withHC or \
82-
len(str_list) > LZ4_N_PARALLEL and len(str_list[0]) > LZ4_MINSZ_PARALLEL
82+
def can_parallelize_strlist(strlist):
83+
return len(strlist) > LZ4_N_PARALLEL and len(strlist[0]) > LZ4_MINSZ_PARALLEL
84+
85+
use_parallel = (ENABLE_PARALLEL and withHC) or can_parallelize_strlist(str_list)
8386

8487
if BENCHMARK_MODE or use_parallel:
8588
if _compress_thread_pool is None:

arctic/_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class FwPointersCfg(Enum):
8181
LZ4_N_PARALLEL = os.environ.get('LZ4_N_PARALLEL', 16)
8282

8383
# Minimum data size to use parallel compression
84-
LZ4_MINSZ_PARALLEL = os.environ.get('LZ4_MINSZ_PARALLEL', 0.5*1024**2) # 0.5 MB
84+
LZ4_MINSZ_PARALLEL = os.environ.get('LZ4_MINSZ_PARALLEL', 0.5 * 1024 ** 2) # 0.5 MB
8585

8686
# Enable this when you run the benchmark_lz4.py
8787
BENCHMARK_MODE = False

arctic/arctic.py

+34-38
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,18 @@ def initialize_library(self, library, lib_type=VERSION_STORE, **kwargs):
247247
kwargs :
248248
Arguments passed to the Library type for initialization.
249249
"""
250-
l = ArcticLibraryBinding(self, library)
250+
lib = ArcticLibraryBinding(self, library)
251251
# check that we don't create too many namespaces
252252
# can be disabled check_library_count=False
253253
check_library_count = kwargs.pop('check_library_count', True)
254-
if len(self._conn[l.database_name].list_collection_names()) > 5000 and check_library_count:
254+
if len(self._conn[lib.database_name].list_collection_names()) > 5000 and check_library_count:
255255
raise ArcticException("Too many namespaces %s, not creating: %s" %
256-
(len(self._conn[l.database_name].list_collection_names()), library))
257-
l.set_library_type(lib_type)
258-
LIBRARY_TYPES[lib_type].initialize_library(l, **kwargs)
256+
(len(self._conn[lib.database_name].list_collection_names()), library))
257+
lib.set_library_type(lib_type)
258+
LIBRARY_TYPES[lib_type].initialize_library(lib, **kwargs)
259259
# Add a 10G quota just in case the user is calling this with API.
260-
if not l.get_quota():
261-
l.set_quota(10 * 1024 * 1024 * 1024)
260+
if not lib.get_quota():
261+
lib.set_quota(10 * 1024 * 1024 * 1024)
262262

263263
@mongo_retry
264264
def delete_library(self, library):
@@ -270,19 +270,19 @@ def delete_library(self, library):
270270
library : `str`
271271
The name of the library. e.g. 'library' or 'user.library'
272272
"""
273-
l = ArcticLibraryBinding(self, library)
274-
colname = l.get_top_level_collection().name
275-
if not [c for c in l._db.list_collection_names(False) if re.match(r"^{}([\.].*)?$".format(colname), c)]:
273+
lib = ArcticLibraryBinding(self, library)
274+
colname = lib.get_top_level_collection().name
275+
if not [c for c in lib._db.list_collection_names(False) if re.match(r"^{}([\.].*)?$".format(colname), c)]:
276276
logger.info('Nothing to delete. Arctic library %s does not exist.' % colname)
277277
logger.info('Dropping collection: %s' % colname)
278-
l._db.drop_collection(colname)
279-
for coll in l._db.list_collection_names():
278+
lib._db.drop_collection(colname)
279+
for coll in lib._db.list_collection_names():
280280
if coll.startswith(colname + '.'):
281281
logger.info('Dropping collection: %s' % coll)
282-
l._db.drop_collection(coll)
282+
lib._db.drop_collection(coll)
283283
if library in self._library_cache:
284284
del self._library_cache[library]
285-
del self._library_cache[l.get_name()]
285+
del self._library_cache[lib.get_name()]
286286

287287
def get_library(self, library):
288288
"""
@@ -299,8 +299,8 @@ def get_library(self, library):
299299

300300
try:
301301
error = None
302-
l = ArcticLibraryBinding(self, library)
303-
lib_type = l.get_library_type()
302+
lib = ArcticLibraryBinding(self, library)
303+
lib_type = lib.get_library_type()
304304
except (OperationFailure, AutoReconnect) as e:
305305
error = e
306306

@@ -313,10 +313,10 @@ def get_library(self, library):
313313
elif lib_type not in LIBRARY_TYPES:
314314
raise LibraryNotFoundException("Couldn't load LibraryType '%s' for '%s' (has the class been registered?)" %
315315
(lib_type, library))
316-
instance = LIBRARY_TYPES[lib_type](l)
316+
instance = LIBRARY_TYPES[lib_type](lib)
317317
self._library_cache[library] = instance
318318
# The library official name may be different from 'library': e.g. 'library' vs 'user.library'
319-
self._library_cache[l.get_name()] = instance
319+
self._library_cache[lib.get_name()] = instance
320320
return self._library_cache[library]
321321

322322
def __getitem__(self, key):
@@ -338,8 +338,7 @@ def set_quota(self, library, quota):
338338
quota : `int`
339339
Advisory quota for the library - in bytes
340340
"""
341-
l = ArcticLibraryBinding(self, library)
342-
l.set_quota(quota)
341+
ArcticLibraryBinding(self, library).set_quota(quota)
343342

344343
def get_quota(self, library):
345344
"""
@@ -350,8 +349,7 @@ def get_quota(self, library):
350349
library : `str`
351350
The name of the library. e.g. 'library' or 'user.library'
352351
"""
353-
l = ArcticLibraryBinding(self, library)
354-
return l.get_quota()
352+
return ArcticLibraryBinding(self, library).get_quota()
355353

356354
def check_quota(self, library):
357355
"""
@@ -366,8 +364,7 @@ def check_quota(self, library):
366364
------
367365
arctic.exceptions.QuotaExceededException if the quota has been exceeded
368366
"""
369-
l = ArcticLibraryBinding(self, library)
370-
l.check_quota()
367+
ArcticLibraryBinding(self, library).check_quota()
371368

372369
def rename_library(self, from_lib, to_lib):
373370
"""
@@ -386,18 +383,18 @@ def rename_library(self, from_lib, to_lib):
386383
raise ValueError("Collection can only be renamed in the same database")
387384
to_colname = to_lib.split('.')[1]
388385

389-
l = ArcticLibraryBinding(self, from_lib)
390-
colname = l.get_top_level_collection().name
386+
lib = ArcticLibraryBinding(self, from_lib)
387+
colname = lib.get_top_level_collection().name
391388

392389
logger.info('Renaming collection: %s' % colname)
393-
l._db[colname].rename(to_colname)
394-
for coll in l._db.list_collection_names():
390+
lib._db[colname].rename(to_colname)
391+
for coll in lib._db.list_collection_names():
395392
if coll.startswith(colname + '.'):
396-
l._db[coll].rename(coll.replace(colname, to_colname))
393+
lib._db[coll].rename(coll.replace(colname, to_colname))
397394

398395
if from_lib in self._library_cache:
399396
del self._library_cache[from_lib]
400-
del self._library_cache[l.get_name()]
397+
del self._library_cache[lib.get_name()]
401398

402399
def get_library_type(self, lib):
403400
"""
@@ -408,8 +405,7 @@ def get_library_type(self, lib):
408405
lib: str
409406
the library
410407
"""
411-
l = ArcticLibraryBinding(self, lib)
412-
return l.get_library_type()
408+
return ArcticLibraryBinding(self, lib).get_library_type()
413409

414410

415411
class ArcticLibraryBinding(object):
@@ -565,14 +561,14 @@ def to_gigabytes(bytes_):
565561
remaining_count = remaining / avg_size
566562
if remaining_count < 100 or float(remaining) / self.quota < 0.1:
567563
logger.warning("Mongo Quota: %s %.3f / %.0f GB used" % (
568-
'.'.join([self.database_name, self.library]),
569-
to_gigabytes(size),
570-
to_gigabytes(self.quota)))
564+
'.'.join([self.database_name, self.library]),
565+
to_gigabytes(size),
566+
to_gigabytes(self.quota)))
571567
else:
572568
logger.info("Mongo Quota: %s %.3f / %.0f GB used" % (
573-
'.'.join([self.database_name, self.library]),
574-
to_gigabytes(size),
575-
to_gigabytes(self.quota)))
569+
'.'.join([self.database_name, self.library]),
570+
to_gigabytes(size),
571+
to_gigabytes(self.quota)))
576572

577573
# Set-up a timer to prevent us for checking for a few writes.
578574
# This will check every average half-life

arctic/chunkstore/chunkstore.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -742,13 +742,14 @@ def stats(self):
742742
res['chunks'] = db.command('collstats', self._collection.name)
743743
res['symbols'] = db.command('collstats', self._symbols.name)
744744
res['metadata'] = db.command('collstats', self._mdata.name)
745-
res['totals'] = {'count': res['chunks']['count'],
746-
'size': res['chunks']['size'] + res['symbols']['size'] + res['metadata']['size'],
747-
}
745+
res['totals'] = {
746+
'count': res['chunks']['count'],
747+
'size': res['chunks']['size'] + res['symbols']['size'] + res['metadata']['size'],
748+
}
748749
return res
749750

750751
def has_symbol(self, symbol):
751-
'''
752+
"""
752753
Check if symbol exists in collection
753754
754755
Parameters
@@ -759,5 +760,5 @@ def has_symbol(self, symbol):
759760
Returns
760761
-------
761762
bool
762-
'''
763+
"""
763764
return self._get_symbol_info(symbol) is not None

arctic/date/_daterange.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,22 @@ def intersection(self, other):
8282
Create a new DateRange representing the maximal range enclosed by this range and other
8383
"""
8484
startopen = other.startopen if self.start is None \
85-
else self.startopen if other.start is None \
86-
else other.startopen if self.start < other.start \
87-
else self.startopen if self.start > other.start \
88-
else (self.startopen or other.startopen)
85+
else self.startopen if other.start is None \
86+
else other.startopen if self.start < other.start \
87+
else self.startopen if self.start > other.start \
88+
else (self.startopen or other.startopen)
8989
endopen = other.endopen if self.end is None \
90-
else self.endopen if other.end is None \
91-
else other.endopen if self.end > other.end \
92-
else self.endopen if self.end < other.end \
93-
else (self.endopen or other.endopen)
90+
else self.endopen if other.end is None \
91+
else other.endopen if self.end > other.end \
92+
else self.endopen if self.end < other.end \
93+
else (self.endopen or other.endopen)
9494

9595
new_start = self.start if other.start is None \
96-
else other.start if self.start is None \
97-
else max(self.start, other.start)
96+
else other.start if self.start is None \
97+
else max(self.start, other.start)
9898
new_end = self.end if other.end is None \
99-
else other.end if self.end is None \
100-
else min(self.end, other.end)
99+
else other.end if self.end is None \
100+
else min(self.end, other.end)
101101

102102
interval = INTERVAL_LOOKUP[(startopen, endopen)]
103103

arctic/date/_util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def string_to_daterange(str_range, delimiter='-', as_dates=False, interval=CLOSE
8585
def to_dt(date, default_tz=None):
8686
"""
8787
Returns a non-naive datetime.datetime.
88-
88+
8989
Interprets numbers as ms-since-epoch.
9090
9191
Parameters
@@ -116,7 +116,7 @@ def to_pandas_closed_closed(date_range, add_tz=True):
116116
117117
Parameters
118118
----------
119-
date_range : `DateRange` object
119+
date_range : `DateRange` object
120120
converted to CLOSED_CLOSED form for Pandas slicing
121121
122122
add_tz : `bool`

arctic/fixtures/arctic.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def arctic_secondary(mongo_server, arctic):
3535
arctic = m.Arctic(mongo_host=mongo_server.api, allow_secondary=True)
3636
return arctic
3737

38+
3839
@pytest.fixture(scope="function")
3940
def multicolumn_store_with_uncompressed_write(mongo_server):
4041
"""

arctic/scripts/arctic_fsck.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ def main():
5555
final_stats['versions'].get('avgObjSize', 0) / 1024. / 1024.))
5656
logger.info("Versions: %10.2fMB Change(+/-) %.2fMB" %
5757
(final_stats['versions']['size'] / 1024. / 1024.,
58-
(final_stats['versions']['size'] - orig_stats['versions']['size']) / 1024. / 1024.))
58+
(final_stats['versions']['size'] - orig_stats['versions']['size']) / 1024. / 1024.))
5959
logger.info('Chunk Count: %7d Change(+/-) %6d (av: %.2fMB)' %
6060
(final_stats['chunks']['count'],
6161
final_stats['chunks']['count'] - orig_stats['chunks']['count'],
6262
final_stats['chunks'].get('avgObjSize', 0) / 1024. / 1024.))
6363
logger.info("Chunks: %12.2fMB Change(+/-) %6.2fMB" %
6464
(final_stats['chunks']['size'] / 1024. / 1024.,
65-
(final_stats['chunks']['size'] - orig_stats['chunks']['size']) / 1024. / 1024.))
65+
(final_stats['chunks']['size'] - orig_stats['chunks']['size']) / 1024. / 1024.))
6666
logger.info('----------------------------')
6767

6868
if not opts.f:

arctic/scripts/arctic_init_library.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ def main():
2626
parser.add_argument("--host", default='localhost', help="Hostname, or clustername. Default: localhost")
2727
parser.add_argument("--library", help="The name of the library. e.g. 'arctic_jblackburn.lib'")
2828
parser.add_argument("--type", default=VERSION_STORE, choices=sorted(LIBRARY_TYPES.keys()),
29-
help="The type of the library, as defined in "
30-
"arctic.py. Default: %s" % VERSION_STORE)
29+
help="The type of the library, as defined in "
30+
"arctic.py. Default: %s" % VERSION_STORE)
3131
parser.add_argument("--quota", default=10, help="Quota for the library in GB. A quota of 0 is unlimited."
3232
"Default: 10")
33-
parser.add_argument("--hashed", action="store_true", default=False, help="Use hashed based sharding. Useful where SYMBOLs share a common prefix (e.g. Bloomberg BBGXXXX symbols)"
34-
"Default: False")
33+
parser.add_argument(
34+
"--hashed",
35+
action="store_true",
36+
default=False,
37+
help="Use hashed based sharding. Useful where SYMBOLs share a common prefix (e.g. Bloomberg BBGXXXX symbols) "
38+
"Default: False")
3539

3640
opts = parser.parse_args()
3741

arctic/serialization/incremental.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,23 @@ def _generator(self, from_idx, to_idx, get_bytes=False):
196196
# Note that the range is: [from_idx, to_idx)
197197
self._lazy_init()
198198

199-
my_lenth = len(self)
199+
my_length = len(self)
200200

201201
# Take into account default arguments and negative indexing (from end offset)
202202
from_idx = 0 if from_idx is None else from_idx
203203
if from_idx < 0:
204-
from_idx = my_lenth + from_idx
205-
to_idx = my_lenth if to_idx is None else min(to_idx, my_lenth)
204+
from_idx = my_length + from_idx
205+
to_idx = my_length if to_idx is None else min(to_idx, my_length)
206206
if to_idx < 0:
207-
to_idx = my_lenth + to_idx
207+
to_idx = my_length + to_idx
208208

209209
# No data, finish iteration
210-
if my_lenth == 0 or from_idx >= my_lenth or from_idx >= to_idx:
210+
if my_length == 0 or from_idx >= my_length or from_idx >= to_idx:
211211
return
212212

213213
# Perform serialization for each chunk
214214
while from_idx < to_idx:
215-
curr_stop = min(from_idx+self._rows_per_chunk, to_idx)
215+
curr_stop = min(from_idx + self._rows_per_chunk, to_idx)
216216

217217
chunk, _ = self._serializer.serialize(
218218
self.input_data[from_idx: curr_stop],

arctic/serialization/numpy_arrays.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def serialize(self, df):
186186
return ret
187187

188188
def deserialize(self, data, columns=None):
189-
'''
189+
"""
190190
Deserializes SON to a DataFrame
191191
192192
Parameters
@@ -199,8 +199,8 @@ def deserialize(self, data, columns=None):
199199
Returns
200200
-------
201201
pandas dataframe or series
202-
'''
203-
if data == []:
202+
"""
203+
if not data:
204204
return pd.DataFrame()
205205

206206
meta = data[0][METADATA] if isinstance(data, list) else data[METADATA]

arctic/serialization/numpy_records.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
from pandas import DataFrame, MultiIndex, Series, DatetimeIndex, Index
55

6+
# Used in global scope, do not remove.
67
from .._config import FAST_CHECK_DF_SERIALIZABLE
78
from .._util import NP_OBJECT_DTYPE
89
from ..exceptions import ArcticException

0 commit comments

Comments
 (0)