class_docstr: Dynamic Instruments Filter Abstract class to filter a series of certain features
  
  Filters should provide parameters:
  
  - filter start time
  - filter end time
  - filter rule
  
  Override __init__ to assign a certain rule to filter the series.
  
  Override _getFilterSeries to use the rule to filter the series and get a dict of {inst => series}, or override filter_main for more advanced series filter rule
class_docstr_tok: ["Dynamic","Instruments","Filter","Abstract","class","to","filter","a","series","of","certain","features","Filters","should","provide","parameters",":","-","filter","start","time","-","filter","end","time","-","filter","rule","Override","__init__","to","assign","a","certain","rule","to","filter","the","series",".","Override","_getFilterSeries","to","use","the","rule","to","filter","the","series","and","get","a","dict","of","{","inst","=",">","series","}",",","or","override","filter_main","for","more","advanced","series","filter","rule"]
docstr: Implement this method to filter the instruments.
  
  Parameters
  ----------
  instruments: dict
      input instruments to be filtered.
  start_time: str
      start of the time range.
  end_time: str
      end of the time range.
  
  Returns
  ----------
  dict
      filtered instruments, same structure as input instruments.
docstr_tok: ["Implement","this","method","to","filter","the","instruments",".","Parameters","--","--","--","--","--","instruments",":","dict","input","instruments","to","be","filtered",".","start_time",":","str","start","of","the","time","range",".","end_time",":","str","end","of","the","time","range",".","Returns","--","--","--","--","--","dict","filtered","instruments",",","same","structure","as","input","instruments","."]
code: def filter_main(self, instruments, start_time=None, end_time=None):
      """Implement this method to filter the instruments.
  
      Parameters
      ----------
      instruments: dict
          input instruments to be filtered.
      start_time: str
          start of the time range.
      end_time: str
          end of the time range.
  
      Returns
      ----------
      dict
          filtered instruments, same structure as input instruments.
      """
      lbound, ubound = self._getTimeBound(instruments)
      start_time = pd.Timestamp(start_time or lbound)
      end_time = pd.Timestamp(end_time or ubound)
      _instruments_filtered = {}
      _all_calendar = Cal.calendar(
          start_time=start_time,
          end_time=end_time,
          freq=self.filter_freq,
      )
      _filter_calendar = Cal.calendar(
          start_time=self.filter_start_time
          and max(self.filter_start_time, _all_calendar[0])
          or _all_calendar[0],
          end_time=self.filter_end_time
          and min(self.filter_end_time, _all_calendar[-1])
          or _all_calendar[-1],
          freq=self.filter_freq,
      )
      _all_filter_series = self._getFilterSeries(
          instruments, _filter_calendar[0], _filter_calendar[-1]
      )
      for inst, timestamp in instruments.items():
          # Construct a whole map of date
          _timestamp_series = self._toSeries(_all_calendar, timestamp)
          # Get filter series
          if inst in _all_filter_series:
              _filter_series = _all_filter_series[inst]
          else:
              if self.keep:
                  _filter_series = pd.Series(
                      {
                          timestamp: True
                          for timestamp in _filter_calendar
                      }
                  )
              else:
                  _filter_series = pd.Series(
                      {
                          timestamp: False
                          for timestamp in _filter_calendar
                      }
                  )
          # Calculate bool value within the range of filter
          _timestamp_series = self._filterSeries(
              _timestamp_series, _filter_series
          )
          # Reform the map to (start_timestamp, end_timestamp) format
          _timestamp = self._toTimestamp(_timestamp_series)
          # Remove empty timestamp
          if _timestamp:
              _instruments_filtered[inst] = _timestamp
      return _instruments_filtered
  
imports: from __future__ import print_function
  from abc import abstractmethod
  import re
  import pandas
  import numpy
  import abc
  from .data import Cal, DatasetD
label_desc: Use image node_id 8 for calling the SeriesDFilter obj's underlying member method code with example usage: obj.filter_main(instruments, start_time, end_time) and returns: _instruments_filtered