def prev(self, t):
        """Using the timesteps set of this model instance, return `t-1`,
        even if the set is not continuous.

        E.g., if t is [0, 1, 2, 6, 7, 8], model.prev(6) will return 2.

        """
        # Create an index to look up t, and save it for later use
        try:
            # Check if _t_index exists
            self._t_index.name
        except __HOLE__:
            self._t_index = pd.Index(self.data._dt.index)
        # Get the location of t in the index and use it to retrieve
        # the desired value, raising an error if it's <0
        loc = self._t_index.get_loc(t) - 1
        if loc >= 0:
            return self.data._dt.index[loc]
        else:
            e = exceptions.ModelError
            raise e('Attempted to get a timestep earlier than the first one.')
dataset/ETHPy150Open calliope-project/calliope/calliope/core.py/Model.prev