code: def resam_ts_data(
      ts_feature: Union[pd.DataFrame, pd.Series],
      start_time: Union[str, pd.Timestamp] = None,
      end_time: Union[str, pd.Timestamp] = None,
      method: Union[str, Callable] = "last",
      method_kwargs: dict = {},
  ):
      """
      Resample value from time-series data
  
          - If `feature` has MultiIndex[instrument, datetime], apply the `method` to each instruemnt data with datetime in [start_time, end_time]
              Example:
  
              .. code-block::
  
                  print(feature)
                                          $close      $volume
                  instrument  datetime
                  SH600000    2010-01-04  86.778313   16162960.0
                              2010-01-05  87.433578   28117442.0
                              2010-01-06  85.713585   23632884.0
                              2010-01-07  83.788803   20813402.0
                              2010-01-08  84.730675   16044853.0
  
                  SH600655    2010-01-04  2699.567383  158193.328125
                              2010-01-08  2612.359619   77501.406250
                              2010-01-11  2712.982422  160852.390625
                              2010-01-12  2788.688232  164587.937500
                              2010-01-13  2790.604004  145460.453125
  
                  print(resam_ts_data(feature, start_time="2010-01-04", end_time="2010-01-05", fields=["$close", "$volume"], method="last"))
                              $close      $volume
                  instrument
                  SH600000    87.433578 28117442.0
                  SH600655    2699.567383  158193.328125
  
          - Else, the `feature` should have Index[datetime], just apply the `method` to `feature` directly
              Example:
  
              .. code-block::
                  print(feature)
                              $close      $volume
                  datetime
                  2010-01-04  86.778313   16162960.0
                  2010-01-05  87.433578   28117442.0
                  2010-01-06  85.713585   23632884.0
                  2010-01-07  83.788803   20813402.0
                  2010-01-08  84.730675   16044853.0
  
                  print(resam_ts_data(feature, start_time="2010-01-04", end_time="2010-01-05", method="last"))
  
                  $close 87.433578
                  $volume 28117442.0
  
                  print(resam_ts_data(feature['$close'], start_time="2010-01-04", end_time="2010-01-05", method="last"))
  
                  87.433578
  
      Parameters
      ----------
      ts_feature : Union[pd.DataFrame, pd.Series]
          Raw time-series feature to be resampled
      start_time : Union[str, pd.Timestamp], optional
          start sampling time, by default None
      end_time : Union[str, pd.Timestamp], optional
          end sampling time, by default None
      method : Union[str, Callable], optional
          sample method, apply method function to each stock series data, by default "last"
          - If type(method) is str or callable function, it should be an attribute of SeriesGroupBy or DataFrameGroupby, and applies groupy.method for the sliced time-series data
          - If method is None, do nothing for the sliced time-series data.
      method_kwargs : dict, optional
          arguments of method, by default {}
  
      Returns
      -------
          The resampled DataFrame/Series/value, return None when the resampled data is empty.
      """
  
      selector_datetime = slice(start_time, end_time)
  
      from ..data.dataset.utils import (
          get_level_index,
      )  # pylint: disable=C0415
  
      feature = lazy_sort_index(ts_feature)
  
      datetime_level = get_level_index(feature, level="datetime") == 0
      if datetime_level:
          feature = feature.loc[selector_datetime]
      else:
          feature = feature.loc(axis=0)[
              (slice(None), selector_datetime)
          ]
  
      if feature.empty:
          return None
      if isinstance(feature.index, pd.MultiIndex):
          if callable(method):
              method_func = method
              return feature.groupby(level="instrument").apply(
                  method_func, **method_kwargs
              )
          elif isinstance(method, str):
              return getattr(
                  feature.groupby(level="instrument"), method
              )(**method_kwargs)
      else:
          if callable(method):
              method_func = method
              return method_func(feature, **method_kwargs)
          elif isinstance(method, str):
              return getattr(feature, method)(**method_kwargs)
      return feature
  
file_path: qlib/qlib/utils/resam.py
imports: import numpy
  import pandas
  from functools import partial
  from typing import Union, Callable
  from .None import lazy_sort_index
  from .time import Freq, cal_sam_minute
  from ..config import C
label_desc: Use image node_id 3 for calling a global function with example usage: resam_ts_data(ts_feature, start_time, end_time, method, method_kwargs) and returns: feature, None, feature, method_func, getattr, getattr