def test_transform(self): """Check if it transforms properly.""" t = OneHotEncode(3) assert numpy.all(t.transform(0) == numpy.array((1., 0., 0.))) assert numpy.all(t.transform(1) == numpy.array((0., 1., 0.))) assert numpy.all(t.transform(2) == numpy.array((0., 0., 1.))) with pytest.raises(AssertionError): t.transform(4) with pytest.raises(AssertionError): t.transform(-1) with pytest.raises(AssertionError): t.transform(2.2) assert(numpy.all(t.transform([[2, 1], [0, 2]]) == numpy.array([[(0., 0., 1.), (0., 1., 0.)], [(1., 0., 0.), (0., 0., 1.)]]))) t = OneHotEncode(2) assert t.transform(0) == 0. assert t.transform(1) == 1. with pytest.raises(TypeError): t.transform('ipsi') assert(numpy.all(t.transform([[1, 1], [0, 1]]) == numpy.array([[1., 1.], [0., 1.]]))) # for the crazy enough t = OneHotEncode(1) assert t.transform(0) == 0. with pytest.raises(TypeError): t.transform('ipsi') assert numpy.all(t.transform([[0, 0], [0, 0]]) == [[0., 0.], [0., 0.]])
def test_deepcopy(self): """Verify that the transformation object can be copied""" t = OneHotEncode(3) t.transform([2]) copy.deepcopy(t)