# Buggy code
def tensor_to_df(
    self,
    tensor: torch.LongTensor,
    **kwargs: Union[torch.Tensor, np.ndarray, Sequence],
) -> pd.DataFrame:
    """Take a tensor of triples and make a pandas dataframe with labels.

    :param tensor: shape: (n, 3)
        The triples, ID-based and in format (head_id, relation_id, tail_id).
    :param kwargs:
        Any additional number of columns. Each column needs to be of shape (n,). Reserved column names:
        {"head_id", "head_label", "relation_id", "relation_label", "tail_id", "tail_label"}.
    :return:
        A dataframe with n rows, and 6 + len(kwargs) columns.
    """
    # Input validation
    additional_columns = set(kwargs.keys())
    forbidden = additional_columns.intersection(TRIPLES_DF_COLUMNS)
    if len(forbidden) > 0:
        raise ValueError(
            f"The key-words for additional arguments must not be in {TRIPLES_DF_COLUMNS}, but {forbidden} were "
            f"used.",
        )

    # convert to numpy
    tensor = tensor.cpu().numpy()
    data = dict(zip(["head_id", "relation_id", "tail_id"], tensor.T))

    # vectorized label lookup
    entity_id_to_label = np.vectorize(self.entity_id_to_label.__getitem__)
    relation_id_to_label = np.vectorize(self.relation_id_to_label.__getitem__)
    for column, id_to_label in dict(
        head=entity_id_to_label,
        relation=relation_id_to_label,
        tail=entity_id_to_label,
    ).items():
        data[f"{column}_label"] = id_to_label(data[f"{column}_id"])

    # Additional columns
    for key, values in kwargs.items():
        # convert PyTorch tensors to numpy
        if torch.is_tensor(values):
            values = values.cpu().numpy()
        data[key] = values

    # convert to dataframe
    rv = pd.DataFrame(data=data)

    # Re-order columns
    columns = list(TRIPLES_DF_COLUMNS) + sorted(
        set(rv.columns).difference(TRIPLES_DF_COLUMNS)
    )
    return rv.loc[:, columns]


# Traceback (KeyError)
Traceback (most recent call last):
File "/Users/cthoyt/dev/pykeen/scratch/tst.py", line 49, in <module>
main()
File "/Users/cthoyt/dev/pykeen/scratch/tst.py", line 36, in main
testing.new_with_restriction(relations=evaluation_relation_whitelist)
File "/Users/cthoyt/dev/pykeen/src/pykeen/triples/triples_factory.py", line 641, in new_with_restriction
relations = list(relations) + list(map(self.relation_to_inverse.__getitem__, relations))
KeyError: 'accusation_inverse'

# Fixed code
def tensor_to_df(
    self,
    tensor: torch.LongTensor,
    **kwargs: Union[torch.Tensor, np.ndarray, Sequence],
) -> pd.DataFrame:
    """Take a tensor of triples and make a pandas dataframe with labels.

    :param tensor: shape: (n, 3)
        The triples, ID-based and in format (head_id, relation_id, tail_id).
    :param kwargs:
        Any additional number of columns. Each column needs to be of shape (n,). Reserved column names:
        {"head_id", "head_label", "relation_id", "relation_label", "tail_id", "tail_label"}.
    :return:
        A dataframe with n rows, and 6 + len(kwargs) columns.
    """
    # Input validation
    additional_columns = set(kwargs.keys())
    forbidden = additional_columns.intersection(TRIPLES_DF_COLUMNS)
    if len(forbidden) > 0:
        raise ValueError(
            f"The key-words for additional arguments must not be in {TRIPLES_DF_COLUMNS}, but {forbidden} were "
            f"used.",
        )

    # convert to numpy
    tensor = tensor.cpu().numpy()
    data = dict(zip(["head_id", "relation_id", "tail_id"], tensor.T))

    # vectorized label lookup
    for column, id_to_label in dict(
        head=self._vectorized_entity_labeler,
        relation=self._vectorized_relation_labeler,
        tail=self._vectorized_entity_labeler,
    ).items():
        data[f"{column}_label"] = id_to_label(data[f"{column}_id"])

    # Additional columns
    for key, values in kwargs.items():
        # convert PyTorch tensors to numpy
        if torch.is_tensor(values):
            values = values.cpu().numpy()
        data[key] = values

    # convert to dataframe
    rv = pd.DataFrame(data=data)

    # Re-order columns
    columns = list(TRIPLES_DF_COLUMNS) + sorted(
        set(rv.columns).difference(TRIPLES_DF_COLUMNS)
    )
    return rv.loc[:, columns]