code: def _sort_and_filter_fits(models):
      """Sort the results in ascending order, by information criterion
  
      If there are no suitable models, raise a ValueError.
      Otherwise, return ``a``. In the case that ``a`` is an iterable
      (i.e., it made it to the end of the function), this method will
      filter out the None values and assess whether the list is empty.
  
      Parameters
      ----------
      models : tuple or list
          The list or (model, fit_time, information_criterion), or a single tuple
      """
      # if it's a result of making it to the end, it will be a list of models
      if not isinstance(models, list):
          models = [models]
  
      # Filter out the Nones or Infs (the failed models)...
      filtered = [
          (mod, ic)
          for mod, _, ic in models
          if mod is not None and np.isfinite(ic)
      ]
  
      # if the list is empty, or if it was an ARIMA and it's None
      if not filtered:
          raise ValueError(
              "Could not successfully fit a viable ARIMA model "
              "to input data.\nSee "
              "http://alkaline-ml.com/pmdarima/no-successful-model.html "
              "for more information on why this can happen."
          )
  
      # sort by the criteria - lower is better for both AIC and BIC
      # (https://stats.stackexchange.com/questions/81427/aic-guidelines-in-model-selection)  # noqa
      sorted_res = sorted(filtered, key=(lambda mod_ic: mod_ic[1]))
  
      # TODO: break ties with fit time?
      models, _ = zip(*sorted_res)
  
      return models
  
imports: from numpy.linalg import LinAlgError
  import numpy
  from datetime import datetime
  from joblib import Parallel, delayed
  from sklearn.utils import check_random_state
  import abc
  import functools
  import time
  import warnings
  import traceback
  from .arima import ARIMA
  from ..warnings import ModelFitWarning
  from ._context import ContextType, ContextStore
  from .None import _validation
  from ..compat import statsmodels
label_desc: Use image node_id 3 for calling a global function with example usage: _sort_and_filter_fits(models) and returns: models