| Conditions | 4 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | from abc import ( |
||
| 67 | def _write_internal(self, directory, iterator, sid_path_func=None): |
||
| 68 | first_open = pd.Timestamp( |
||
| 69 | datetime( |
||
| 70 | year=2002, |
||
| 71 | month=1, |
||
| 72 | day=2, |
||
| 73 | hour=9, |
||
| 74 | minute=31 |
||
| 75 | ), tz='US/Eastern').tz_convert('UTC') |
||
| 76 | |||
| 77 | for asset_id, df in iterator: |
||
| 78 | if sid_path_func is None: |
||
| 79 | path = join(directory, "{0}.bcolz".format(asset_id)) |
||
| 80 | else: |
||
| 81 | path = sid_path_func(directory, asset_id) |
||
| 82 | |||
| 83 | os.makedirs(path) |
||
| 84 | |||
| 85 | minutes = self.full_minutes_for_days(_writer_env, |
||
| 86 | first_open, df.index[-1]) |
||
| 87 | minutes_count = len(minutes) |
||
| 88 | |||
| 89 | dt_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 90 | open_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 91 | high_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 92 | low_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 93 | close_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 94 | vol_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 95 | |||
| 96 | for row in df.iterrows(): |
||
| 97 | dt = row[0] |
||
| 98 | idx = minutes.searchsorted(dt) |
||
| 99 | |||
| 100 | dt_col[idx] = dt.value / 1e9 |
||
| 101 | open_col[idx] = row[1].loc["open"] |
||
| 102 | high_col[idx] = row[1].loc["high"] |
||
| 103 | low_col[idx] = row[1].loc["low"] |
||
| 104 | close_col[idx] = row[1].loc["close"] |
||
| 105 | vol_col[idx] = row[1].loc["volume"] |
||
| 106 | |||
| 107 | ctable( |
||
| 108 | columns=[ |
||
| 109 | open_col, |
||
| 110 | high_col, |
||
| 111 | low_col, |
||
| 112 | close_col, |
||
| 113 | vol_col, |
||
| 114 | dt_col |
||
| 115 | ], |
||
| 116 | names=[ |
||
| 117 | "open", |
||
| 118 | "high", |
||
| 119 | "low", |
||
| 120 | "close", |
||
| 121 | "volume", |
||
| 122 | "dt" |
||
| 123 | ], |
||
| 124 | rootdir=path, |
||
| 125 | mode='w' |
||
| 126 | ) |
||
| 186 |