read_cache_from This function can read data from the disk cache dataset :param cache_path: :param start_time: :param end_time: :param fields: The fields order of the dataset cache is sorted. So rearrange the columns to make it consistent. :return:
(cls, cache_path: Union[str, Path], start_time, end_time, fields)
| 660 | |
| 661 | @classmethod |
| 662 | def read_data_from_cache(cls, cache_path: Union[str, Path], start_time, end_time, fields): |
| 663 | """read_cache_from |
| 664 | |
| 665 | This function can read data from the disk cache dataset |
| 666 | |
| 667 | :param cache_path: |
| 668 | :param start_time: |
| 669 | :param end_time: |
| 670 | :param fields: The fields order of the dataset cache is sorted. So rearrange the columns to make it consistent. |
| 671 | :return: |
| 672 | """ |
| 673 | |
| 674 | im = DiskDatasetCache.IndexManager(cache_path) |
| 675 | index_data = im.get_index(start_time, end_time) |
| 676 | if index_data.shape[0] > 0: |
| 677 | start, stop = ( |
| 678 | index_data["start"].iloc[0].item(), |
| 679 | index_data["end"].iloc[-1].item(), |
| 680 | ) |
| 681 | else: |
| 682 | start = stop = 0 |
| 683 | |
| 684 | with pd.HDFStore(cache_path, mode="r") as store: |
| 685 | if "/{}".format(im.KEY) in store.keys(): |
| 686 | df = store.select(key=im.KEY, start=start, stop=stop) |
| 687 | df = df.swaplevel("datetime", "instrument").sort_index() |
| 688 | # read cache and need to replace not-space fields to field |
| 689 | df = cls.cache_to_origin_data(df, fields) |
| 690 | |
| 691 | else: |
| 692 | df = pd.DataFrame(columns=fields) |
| 693 | return df |
| 694 | |
| 695 | def _dataset( |
| 696 | self, instruments, fields, start_time=None, end_time=None, freq="day", disk_cache=0, inst_processors=[] |
no test coverage detected