Пример #1
0
def test_inverse_transform(orig_label, ord_label, expected_reverted,
                           bad_ord_label):
    # prepare LabelEncoder
    le = LabelEncoder()
    le.fit(orig_label)
    assert (le._fitted is True)

    # test if inverse_transform is correct
    reverted = le.inverse_transform(ord_label)
    assert (len(reverted) == len(expected_reverted))
    assert (len(reverted) == len(reverted[reverted == expected_reverted]))
    # test if correctly raies ValueError
    with pytest.raises(ValueError, match='y contains previously unseen label'):
        le.inverse_transform(bad_ord_label)
Пример #2
0
def test_empty_input(empty, ord_label):
    # prepare LabelEncoder
    le = LabelEncoder()
    le.fit(empty)
    assert (le._fitted is True)

    # test if correctly raies ValueError
    with pytest.raises(ValueError, match='y contains previously unseen label'):
        le.inverse_transform(ord_label)

    # check fit_transform()
    le = LabelEncoder()
    transformed = le.fit_transform(empty)
    assert (le._fitted is True)
    assert (len(transformed) == 0)