code: def require_variable(self, variable, unit=None, year=None,
                           exclude_on_fail=False):
          
          criteria = {'variable': variable}
          if unit:
              criteria.update({'unit': unit})
          if year:
              criteria.update({'year': year})
  
          keep = self._apply_filters(**criteria)
          idx = self.meta.index.difference(_meta_idx(self.data[keep]))
  
          n = len(idx)
          if n == 0:
              logger().info('All scenarios have the required variable `{}`'
                            .format(variable))
              return
  
          msg = '{} scenario does not include required variable `{}`' if n == 1 \
              else '{} scenarios do not include required variable `{}`'
  
          if exclude_on_fail:
              self.meta.loc[idx, 'exclude'] = True
              msg += ', marked as `exclude: True` in metadata'
  
          logger().info(msg.format(n, variable))
          return pd.DataFrame(index=idx).reset_index()
docs: Check whether all scenarios have a required variable
  
          Parameters
          ----------
          variable: str
              required variable
          unit: str, default None
              name of unit (optional)
          year: int or list, default None
              years (optional)
          exclude_on_fail: bool, default False
              flag scenarios missing the required variables as `exclude: True`