MCPcopy Index your code
hub / github.com/microsoft/qlib / _data_to_bin

Method _data_to_bin

scripts/dump_bin.py:245–269  ·  view source on GitHub ↗
(self, df: pd.DataFrame, calendar_list: List[pd.Timestamp], features_dir: Path)

Source from the content-addressed store, hash-verified

243 return calendar_list.index(df.index.min())
244
245 def _data_to_bin(self, df: pd.DataFrame, calendar_list: List[pd.Timestamp], features_dir: Path):
246 if df.empty:
247 logger.warning(f"{features_dir.name} data is None or empty")
248 return
249 if not calendar_list:
250 logger.warning("calendar_list is empty")
251 return
252 # align index
253 _df = self.data_merge_calendar(df, calendar_list)
254 if _df.empty:
255 logger.warning(f"{features_dir.name} data is not in calendars")
256 return
257 # used when creating a bin file
258 date_index = self.get_datetime_index(_df, calendar_list)
259 for field in self.get_dump_fields(_df.columns):
260 bin_path = features_dir.joinpath(f"{field.lower()}.{self.freq}{self.DUMP_FILE_SUFFIX}")
261 if field not in _df.columns:
262 continue
263 if bin_path.exists() and self._mode == self.UPDATE_MODE:
264 # update
265 with bin_path.open("ab") as fp:
266 np.array(_df[field]).astype("<f").tofile(fp)
267 else:
268 # append; self._mode == self.ALL_MODE or not bin_path.exists()
269 np.hstack([date_index, _df[field]]).astype("<f").tofile(str(bin_path.resolve()))
270
271 def _dump_bin(self, file_or_data: [Path, pd.DataFrame], calendar_list: List[pd.Timestamp]):
272 if not calendar_list:

Callers 1

_dump_binMethod · 0.95

Calls 4

data_merge_calendarMethod · 0.95
get_datetime_indexMethod · 0.95
get_dump_fieldsMethod · 0.95
existsMethod · 0.45

Tested by

no test coverage detected