class_docstr: Find appropriate date and adjust date.
class_docstr_tok: ["Find","appropriate","date","and","adjust","date","."]
docstr: Align the given date to the trade date
  
  for example:
  
      .. code-block:: python
  
          input: {'train': ('2008-01-01', '2014-12-31'), 'valid': ('2015-01-01', '2016-12-31'), 'test': ('2017-01-01', '2020-08-01')}
  
          output: {'train': (Timestamp('2008-01-02 00:00:00'), Timestamp('2014-12-31 00:00:00')),
                  'valid': (Timestamp('2015-01-05 00:00:00'), Timestamp('2016-12-30 00:00:00')),
                  'test': (Timestamp('2017-01-03 00:00:00'), Timestamp('2020-07-31 00:00:00'))}
  
  Parameters
  ----------
  segment
  
  Returns
  -------
  Union[dict, tuple]: the start and end trade date (pd.Timestamp) between the given start and end date.
docstr_tok: ["Align","the","given","date","to","the","trade","date","for","example",":","..","code-block",":",":","python","input",":","{","'train","'",":","(","'2008-01-01","'",",","'2014-12-31","'",")",",","'valid","'",":","(","'2015-01-01","'",",","'2016-12-31","'",")",",","'test","'",":","(","'2017-01-01","'",",","'2020-08-01","'",")","}","output",":","{","'train","'",":","(","Timestamp","(","'2008-01-02","00:00:00","'",")",",","Timestamp","(","'2014-12-31","00:00:00","'",")",")",",","'valid","'",":","(","Timestamp","(","'2015-01-05","00:00:00","'",")",",","Timestamp","(","'2016-12-30","00:00:00","'",")",")",",","'test","'",":","(","Timestamp","(","'2017-01-03","00:00:00","'",")",",","Timestamp","(","'2020-07-31","00:00:00","'",")",")","}","Parameters","--","--","--","--","--","segment","Returns","--","--","--","-","Union","[","dict",",","tuple","]",":","the","start","and","end","trade","date","(","pd.Timestamp",")","between","the","given","start","and","end","date","."]
code: def align_seg(
      self, segment: Union[dict, tuple]
  ) -> Union[dict, tuple]:
      """
      Align the given date to the trade date
  
      for example:
  
          .. code-block:: python
  
              input: {'train': ('2008-01-01', '2014-12-31'), 'valid': ('2015-01-01', '2016-12-31'), 'test': ('2017-01-01', '2020-08-01')}
  
              output: {'train': (Timestamp('2008-01-02 00:00:00'), Timestamp('2014-12-31 00:00:00')),
                      'valid': (Timestamp('2015-01-05 00:00:00'), Timestamp('2016-12-30 00:00:00')),
                      'test': (Timestamp('2017-01-03 00:00:00'), Timestamp('2020-07-31 00:00:00'))}
  
      Parameters
      ----------
      segment
  
      Returns
      -------
      Union[dict, tuple]: the start and end trade date (pd.Timestamp) between the given start and end date.
      """
      if isinstance(segment, dict):
          return {k: self.align_seg(seg) for k, seg in segment.items()}
      elif isinstance(segment, (tuple, list)):
          return self.align_time(
              segment[0], tp_type="start"
          ), self.align_time(segment[1], tp_type="end")
      else:
          raise NotImplementedError(
              f"This type of input is not supported"
          )
  
imports: import bisect
  from copy import deepcopy
  import pandas
  from qlib.data import D
  from qlib.utils import hash_args
  from qlib.utils.mod import init_instance_by_config
  from qlib.workflow import R
  from qlib.config import C
  from qlib.log import get_module_logger
  from pymongo import MongoClient
  from pymongo.database import Database
  from typing import Union
  from pathlib import Path
label_desc: Use image node_id 8 for calling the TimeAdjuster obj's underlying member method code with example usage: obj.align_seg(segment) and returns: unknown, self,  self