code: def clean_fill_method(method, allow_nearest=False):
      # asfreq is compat for resampling
      if method in [None, "asfreq"]:
          return None
  
      if isinstance(method, string_types):
          method = method.lower()
          if method == "ffill":
              method = "pad"
          elif method == "bfill":
              method = "backfill"
  
      valid_methods = ["pad", "backfill"]
      expecting = "pad (ffill) or backfill (bfill)"
      if allow_nearest:
          valid_methods.append("nearest")
          expecting = "pad (ffill), backfill (bfill) or nearest"
      if method not in valid_methods:
          msg = "Invalid fill method. Expecting {expecting}. Got {method}".format(
              expecting=expecting, method=method
          )
          raise ValueError(msg)
      return method
  
imports: from distutils.version import LooseVersion
  import operator
  import numpy
  from pandas._libs import algos, lib
  from pandas.compat import range, string_types
  from pandas.core.dtypes.cast import infer_dtype_from_array
  from pandas.core.dtypes.common import ensure_float64, is_datetime64_dtype, is_datetime64tz_dtype, is_float_dtype, is_integer, is_integer_dtype, is_numeric_v_string_like, is_scalar, is_timedelta64_dtype, needs_i8_conversion
  from pandas.core.dtypes.missing import isna
label_desc: Use image node_id 2 for calling a global function with example usage: clean_fill_method(method, allow_nearest) and returns: method, None