numalogic icon indicating copy to clipboard operation
numalogic copied to clipboard

staticpowertransformer throws error intermittently

Open ab93 opened this issue 2 years ago • 0 comments

Intermittently this test case throws this error, mostly because of the random number that is generated.

=================================== FAILURES ===================================
_________________ TestTransformers.test_staticpowertransformer _________________

self = <numalogic.tests.preprocess.test_transformer.TestTransformers testMethod=test_staticpowertransformer>

    def test_staticpowertransformer(self):
        x = 1 + np.random.randn(5, 3)
        transformer = StaticPowerTransformer(3, add_factor=2)
        x_prime = transformer.transform(x)
    
        assert_almost_equal(np.power(2 + x, 3), x_prime)
        assert_almost_equal(transformer.fit_transform(x), x_prime)
>       assert_almost_equal(transformer.inverse_transform(x_prime), x, decimal=4)
E       AssertionError: 
E       Arrays are not almost equal to 4 decimals
E       
E       x and y nan location mismatch:
E        x: array([[1.9392, 3.3033, 0.2871],
E              [1.5581, 1.6368, 2.0375],
E              [0.3713, 3.0054, 1.0976],...
E        y: array([[ 1.9392,  3.3033,  0.2871],
E              [ 1.5581,  1.6368,  2.0375],
E              [ 0.3713,  3.0054,  1.0976],...

numalogic/tests/preprocess/test_transformer.py:26: AssertionError
=============================== warnings summary ===============================
numalogic/tests/preprocess/test_transformer.py::TestTransformers::test_staticpowertransformer
  /home/runner/work/numalogic/numalogic/numalogic/preprocess/transformer.py:41: RuntimeWarning: invalid value encountered in power
    return np.power(X, 1.0 / self.n) - self.add_factor

Need to offset the random number to make sure that test case always passes.

ab93 avatar Oct 17 '22 23:10 ab93