Skip to content

test_pow fails due to differences at machine precision #5981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
drudd opened this issue Jan 16, 2014 · 4 comments
Closed

test_pow fails due to differences at machine precision #5981

drudd opened this issue Jan 16, 2014 · 4 comments
Labels
Testing pandas testing functions or related to the test suite
Milestone

Comments

@drudd
Copy link
Contributor

drudd commented Jan 16, 2014

I am testing pandas 0.13 (built against numexpr 2.2.2, numpy 1.8.0, scipy 0.13.2, all linked to MKL 10.3 using Scientific Linux 6.4's stock gcc 4.7.4), and test_pow fails with an array not equal error:

FAIL: test_pow (pandas.computation.tests.test_eval.TestEvalNumexprPandas)

Traceback (most recent call last):
File "/software/python-2.7-2014q1-el6-x86_64/lib/python2.7/site-packages/pandas/computation/tests/test_eval.py", line 192, in test_pow
self.check_pow(lhs, '*_', rhs)
File "/software/python-2.7-2014q1-el6-x86_64/lib/python2.7/site-packages/pandas/computation/tests/test_eval.py", line 94, in wrapper
f(self, lhs, arith1, rhs, *args, *_kwargs)
File "/software/python-2.7-2014q1-el6-x86_64/lib/python2.7/site-packages/pandas/computation/tests/test_eval.py", line 408, in check_pow
assert_array_equal(result, expected)
File "/software/python-2.7-2014q1-el6-x86_64/lib/python2.7/site-packages/numpy/testing/utils.py", line 718, in assert_array_equal
verbose=verbose, header='Arrays are not equal')
File "/software/python-2.7-2014q1-el6-x86_64/lib/python2.7/site-packages/numpy/testing/utils.py", line 644, in assert_array_compare
raise AssertionError(msg)
AssertionError:
Arrays are not equal

(mismatch 25.8064516129%)
x: array([[ 6.98492548e-01, 5.39900967e-01, 1.87991705e+00,
7.67724670e-01, nan],
[ nan, 1.18493281e+00, 4.15163610e+01,...
y: array([[ 6.98492548e-01, 5.39900967e-01, 1.87991705e+00,
7.67724670e-01, nan],
[ nan, 1.18493281e+00, 4.15163610e+01,...


I have modified the check_pow function in that test to identify the error and print out the difference in result and expected:
@skip_incompatible_operand
def check_pow(self, lhs, arith1, rhs):
ex = 'lhs {0} rhs'.format(arith1)
expected = self.get_expected_pow_result(lhs, rhs)
result = pd.eval(ex, engine=self.engine, parser=self.parser)

    if (np.isscalar(lhs) and np.isscalar(rhs) and
            _is_py3_complex_incompat(result, expected)):
        self.assertRaises(AssertionError, assert_array_equal, result,
                          expected)
    else:
        print result, expected, result-expected
        assert_array_equal(result, expected,verbose=True)

        ex = '(lhs {0} rhs) {0} rhs'.format(arith1)
        result = pd.eval(ex, engine=self.engine, parser=self.parser)
        expected = self.get_expected_pow_result(
            self.get_expected_pow_result(lhs, rhs), rhs)
        print result, expected, result-expected
        assert_array_equal(result, expected)

Which yields the following (only differences reported for brevity):
[10 rows x 5 columns] 0 1 2 3 4
0 -2.775558e-17 NaN 0.000000e+00 -2.220446e-16 0.000000e+00
1 0.000000e+00 1.110223e-16 NaN NaN NaN
2 0.000000e+00 NaN NaN NaN NaN
3 0.000000e+00 NaN NaN 0.000000e+00 0.000000e+00
4 NaN 0.000000e+00 1.110223e-16 0.000000e+00 2.220446e-16
5 NaN -1.110223e-16 -5.551115e-17 0.000000e+00 0.000000e+00
6 NaN NaN 0.000000e+00 NaN -4.440892e-16
7 -1.110223e-16 NaN NaN 3.552714e-15 NaN
8 NaN 0.000000e+00 0.000000e+00 NaN 2.220446e-16
9 0.000000e+00 0.000000e+00 NaN 0.000000e+00 0.000000e+00

and

[10 rows x 5 columns] 0 1 2 3 4
0 0.000000e+00 NaN 0.000000e+00 0.000000e+00 0.000000e+00
1 0.000000e+00 1.110223e-16 NaN NaN NaN
2 2.220446e-16 NaN NaN NaN NaN
3 0.000000e+00 NaN NaN 5.551115e-17 0.000000e+00
4 NaN 0.000000e+00 1.110223e-16 0.000000e+00 2.220446e-16
5 NaN -1.110223e-16 0.000000e+00 0.000000e+00 0.000000e+00
6 NaN NaN 0.000000e+00 NaN 1.110223e-16
7 2.220446e-16 NaN NaN -4.336809e-19 NaN
8 NaN 0.000000e+00 0.000000e+00 NaN -1.110223e-16
9 0.000000e+00 1.110223e-16 NaN 0.000000e+00 0.000000e+00

The differences are only at machine precision, and may be due to the use of MKL rather than standard blas (I haven't dug any further). I have verified that changing the test from assert_array_equal to assert_allclose allows the test to succeed.

@jreback
Copy link
Contributor

jreback commented Jan 16, 2014

gr8

want to do a PR for this?

@drudd
Copy link
Contributor Author

drudd commented Jan 16, 2014

Sure, are there preferred conventions for numerical precision in pandas tests? assert_allclose defaults to 1e-7 I believe.

@jreback
Copy link
Contributor

jreback commented Jan 16, 2014

that's fine (or 1e-5) ok too

drudd pushed a commit to drudd/pandas that referenced this issue Jan 16, 2014
…ssert_allclose rather than assert_all_equal to avoid machine precision failures in TestEvalNumexprPandas/Numpy. Fixes issue pandas-dev#5981.
@jreback
Copy link
Contributor

jreback commented Jan 17, 2014

closed by #5982

@jreback jreback closed this as completed Jan 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

2 participants