| Conditions | 4 |
| Total Lines | 63 |
| 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 ( |
||
| 86 | def _write_internal(self, directory, iterator, sid_path_func=None): |
||
| 87 | first_trading_day = self.first_trading_day |
||
| 88 | |||
| 89 | write_metadata(directory, first_trading_day) |
||
| 90 | |||
| 91 | first_open = pd.Timestamp( |
||
| 92 | datetime( |
||
| 93 | year=first_trading_day.year, |
||
| 94 | month=first_trading_day.month, |
||
| 95 | day=first_trading_day.day, |
||
| 96 | hour=9, |
||
| 97 | minute=31 |
||
| 98 | ), tz='US/Eastern').tz_convert('UTC') |
||
| 99 | |||
| 100 | for asset_id, df in iterator: |
||
| 101 | if sid_path_func is None: |
||
| 102 | path = join(directory, "{0}.bcolz".format(asset_id)) |
||
| 103 | else: |
||
| 104 | path = sid_path_func(directory, asset_id) |
||
| 105 | |||
| 106 | os.makedirs(path) |
||
| 107 | |||
| 108 | minutes = self.full_minutes_for_days(_writer_env, |
||
| 109 | first_open, df.index[-1]) |
||
| 110 | minutes_count = len(minutes) |
||
| 111 | |||
| 112 | dt_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 113 | open_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 114 | high_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 115 | low_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 116 | close_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 117 | vol_col = np.zeros(minutes_count, dtype=np.uint32) |
||
| 118 | |||
| 119 | for row in df.iterrows(): |
||
| 120 | dt = row[0] |
||
| 121 | idx = minutes.searchsorted(dt) |
||
| 122 | |||
| 123 | dt_col[idx] = dt.value / 1e9 |
||
| 124 | open_col[idx] = row[1].loc["open"] |
||
| 125 | high_col[idx] = row[1].loc["high"] |
||
| 126 | low_col[idx] = row[1].loc["low"] |
||
| 127 | close_col[idx] = row[1].loc["close"] |
||
| 128 | vol_col[idx] = row[1].loc["volume"] |
||
| 129 | |||
| 130 | ctable( |
||
| 131 | columns=[ |
||
| 132 | open_col, |
||
| 133 | high_col, |
||
| 134 | low_col, |
||
| 135 | close_col, |
||
| 136 | vol_col, |
||
| 137 | dt_col |
||
| 138 | ], |
||
| 139 | names=[ |
||
| 140 | "open", |
||
| 141 | "high", |
||
| 142 | "low", |
||
| 143 | "close", |
||
| 144 | "volume", |
||
| 145 | "dt" |
||
| 146 | ], |
||
| 147 | rootdir=path, |
||
| 148 | mode='w' |
||
| 149 | ) |
||
| 232 |