Пример #1
0
    def test_hash_numpy_different_values(self):
        hashed1 = get_hash(np.array([1, 2], dtype=np.int64))
        hashed2 = get_hash(np.array([1, 3], dtype=np.int64))

        assert_hash(hashed1)
        assert_hash(hashed2)

        assert hashed1 != hashed2
Пример #2
0
    def test_hash_numpy(self, dtype):
        hashed1 = get_hash(np.array([1, 2], dtype=dtype))
        hashed2 = get_hash(np.array([1, 2], dtype=dtype))

        assert_hash(hashed1)
        assert_hash(hashed2)

        assert hashed1 == hashed2
Пример #3
0
    def test_hash_object_different(self):
        hashed1 = get_hash(dict(a=1, b='x'))
        hashed2 = get_hash(dict(a=2, b='x'))

        assert_hash(hashed1)
        assert_hash(hashed2)

        assert hashed1 != hashed2
Пример #4
0
    def test_hash_object(self):
        hashed1 = get_hash(dict(a=1, b='x'))
        hashed2 = get_hash(dict(a=1, b='x'))

        assert_hash(hashed1)
        assert_hash(hashed2)

        assert hashed1 == hashed2
Пример #5
0
    def test_hash_scalar_different(self, obj):
        hashed1 = get_hash(obj)
        hashed2 = get_hash('different')

        assert_hash(hashed1)
        assert_hash(hashed2)

        assert hashed1 != hashed2
Пример #6
0
    def test_hash_scalar(self, obj):
        hashed1 = get_hash(obj)
        hashed2 = get_hash(obj)

        assert_hash(hashed1)
        assert_hash(hashed2)

        assert hashed1 == hashed2
Пример #7
0
    def test_hash_pandas_different(self):
        df1 = pd.DataFrame(dict(a=[1, 2], b=[3, 4]))
        hashed1 = get_hash(df1)
        df2 = pd.DataFrame(dict(a=[1, 2], b=[2, 4]))
        hashed2 = get_hash(df2)

        assert_hash(hashed1)
        assert_hash(hashed2)

        assert hashed1 != hashed2
Пример #8
0
    def maybe_pure(self, func, inputs, result):
        """
        Check whether the function is pure.

        Actually, it only compares the hash of the function result based on
        its input.
        """
        # inputs is a tuple of args, kwargs
        assert isinstance(inputs, tuple)
        assert len(inputs) == 2
        args, kwargs = inputs

        input_hash = get_hash(*args, **kwargs)
        output_hash = get_hash(result)

        input_key = func.__name__ + '-' + input_hash

        previous_hash = self._update_step_hash(input_key, output_hash)
        maybe_pure = (output_hash == previous_hash)
        if not maybe_pure:
            msg = ('Experiment step result is changed with the same input: '
                   '(step: {}, args: {}, kwargs: {})')
            logger.warning(msg.format(func.__name__, args, kwargs))
        return maybe_pure