def safe_apply()

in sourcecode/scoring/pandas_utils.py [0:0]


  def safe_apply(self) -> Callable:
    """Return a modified apply function that checks type stability."""

    def _safe_apply(*args, **kwargs):
      """Wrapper around pd.DataFrame.apply

      Args:
        args: non-keyword arguments to pass through to merge.
        kwargs: keyword arguments to pass through to merge.
      """
      # TODO: Flesh this out with additional expectatoins around input and output types
      result = self._origApply(*args, **kwargs)
      if isinstance(result, pd.DataFrame):
        self._log_errors("APPLY", self._get_callsite(), self._validate_dataframe(result))
      elif isinstance(result, pd.Series):
        self._log_errors("APPLY", self._get_callsite(), self._validate_series(result))
      return result

    return _safe_apply