Exemplo n.º 1
0
    def test_transform(self):
        """Check if it transforms properly."""
        t = Enumerate([2, 'asfa', 'ipsi'])
        assert t.transform(2) == 0
        assert t.transform('asfa') == 1
        assert t.transform('ipsi') == 2
        with pytest.raises(KeyError):
            t.transform('aafdasfa')
        assert numpy.all(t.transform([['ipsi', 'asfa'], [2, 'ipsi']]) == [[2, 1], [0, 2]])

        # for the crazy enough
        t = Enumerate([2])
        assert t.transform(2) == 0
        with pytest.raises(KeyError):
            t.transform('aafdasfa')
        assert numpy.all(t.transform([[2, 2], [2, 2]]) == [[0, 0], [0, 0]])
Exemplo n.º 2
0
    def test_transform(self):
        """Check if it transforms properly."""
        t = Enumerate([2, "asfa", "ipsi"])
        assert t.transform(2) == 0
        assert t.transform("asfa") == 1
        assert t.transform("ipsi") == 2
        with pytest.raises(KeyError):
            t.transform("aafdasfa")
        assert numpy.all(
            t.transform([["ipsi", "asfa"], [2, "ipsi"]]) == [[2, 1], [0, 2]])

        # for the crazy enough
        t = Enumerate([2])
        assert t.transform(2) == 0
        with pytest.raises(KeyError):
            t.transform("aafdasfa")
        assert numpy.all(t.transform([[2, 2], [2, 2]]) == [[0, 0], [0, 0]])
Exemplo n.º 3
0
 def test_deepcopy(self):
     """Verify that the transformation object can be copied"""
     t = Enumerate([2, 'asfa', 'ipsi'])
     # Copy won't fail if vectorized function is not called at least once.
     t.transform([2])
     copy.deepcopy(t)