(self, instrument, field, start_time=None, end_time=None, freq="day")
| 841 | self.time2idx = time2idx |
| 842 | |
| 843 | def expression(self, instrument, field, start_time=None, end_time=None, freq="day"): |
| 844 | expression = self.get_expression_instance(field) |
| 845 | start_time = time_to_slc_point(start_time) |
| 846 | end_time = time_to_slc_point(end_time) |
| 847 | |
| 848 | # Two kinds of queries are supported |
| 849 | # - Index-based expression: this may save a lot of memory because the datetime index is not saved on the disk |
| 850 | # - Data with datetime index expression: this will make it more convenient to integrating with some existing databases |
| 851 | if self.time2idx: |
| 852 | _, _, start_index, end_index = Cal.locate_index(start_time, end_time, freq=freq, future=False) |
| 853 | lft_etd, rght_etd = expression.get_extended_window_size() |
| 854 | query_start, query_end = max(0, start_index - lft_etd), end_index + rght_etd |
| 855 | else: |
| 856 | start_index, end_index = query_start, query_end = start_time, end_time |
| 857 | |
| 858 | try: |
| 859 | series = expression.load(instrument, query_start, query_end, freq) |
| 860 | except Exception as e: |
| 861 | get_module_logger("data").debug( |
| 862 | f"Loading expression error: " |
| 863 | f"instrument={instrument}, field=({field}), start_time={start_time}, end_time={end_time}, freq={freq}. " |
| 864 | f"error info: {str(e)}" |
| 865 | ) |
| 866 | raise |
| 867 | # Ensure that each column type is consistent |
| 868 | # FIXME: |
| 869 | # 1) The stock data is currently float. If there is other types of data, this part needs to be re-implemented. |
| 870 | # 2) The precision should be configurable |
| 871 | try: |
| 872 | series = series.astype(np.float32) |
| 873 | except ValueError: |
| 874 | pass |
| 875 | except TypeError: |
| 876 | pass |
| 877 | if not series.empty: |
| 878 | series = series.loc[start_index:end_index] |
| 879 | return series |
| 880 | |
| 881 | |
| 882 | class LocalDatasetProvider(DatasetProvider): |
nothing calls this directly
no test coverage detected