Total Complexity | 9 |
Total Lines | 34 |
Duplicated Lines | 0 % |
1 | from numpy import ( |
||
14 | class DailyBarWriterFromDataFrames(BcolzDailyBarWriter): |
||
|
|||
15 | _csv_dtypes = { |
||
16 | 'open': float64, |
||
17 | 'high': float64, |
||
18 | 'low': float64, |
||
19 | 'close': float64, |
||
20 | 'volume': float64, |
||
21 | } |
||
22 | |||
23 | def __init__(self, asset_map): |
||
24 | self._asset_map = asset_map |
||
25 | |||
26 | def gen_tables(self, assets): |
||
27 | for asset in assets: |
||
28 | yield asset, ctable.fromdataframe(assets[asset]) |
||
29 | |||
30 | def to_uint32(self, array, colname): |
||
31 | arrmax = array.max() |
||
32 | if colname in OHLC: |
||
33 | self.check_uint_safe(arrmax * 1000, colname) |
||
34 | return (array * 1000).astype(uint32) |
||
35 | elif colname == 'volume': |
||
36 | self.check_uint_safe(arrmax, colname) |
||
37 | return array.astype(uint32) |
||
38 | elif colname == 'day': |
||
39 | nanos_per_second = (1000 * 1000 * 1000) |
||
40 | self.check_uint_safe(arrmax.view(int) / nanos_per_second, colname) |
||
41 | return (array.view(int) / nanos_per_second).astype(uint32) |
||
42 | |||
43 | @staticmethod |
||
44 | def check_uint_safe(value, colname): |
||
45 | if value >= UINT32_MAX: |
||
46 | raise ValueError( |
||
47 | "Value %s from column '%s' is too large" % (value, colname) |
||
48 | ) |
||
49 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.