code: def get_valid_value(series, last=True):
      """get the first/last not nan value of pd.Series with single level index
      Parameters
      ----------
      series : pd.Series
          series should not be empty
      last : bool, optional
          whether to get the last valid value, by default True
          - if last is True, get the last valid value
          - else, get the first valid value
  
      Returns
      -------
      Nan | float
          the first/last valid value
      """
      return (
          series.fillna(method="ffill").iloc[-1]
          if last
          else series.fillna(method="bfill").iloc[0]
      )
  
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 4 for calling a global function with example usage: get_valid_value(series, last) and returns: unknown