assert_almost_equal / equals should allow access to np.allclose
See original GitHub issueI am testing the equivalence of two large DataFrames (9084x367). The two are the same up to 1x10-13 but when np.array_equal
fails there is a much slower code path (comparing these two frames takes upwards of 20 seconds). If I’m not mistaken, if the arrays aren’t equivalent it does a more complicated version of np.allclose
. I think a good intermediate step would be to check for array equivalence and then as a the second step call np.allclose
–or maybe just do this on the outset. If that fails, which it will if there are any NaNs or if the tolerance is not met, then it will use the current logic. Or we could use np.isclose
to consider NaNs as equivalent.
https://github.com/pydata/pandas/blob/master/pandas/src/testing.pyx#L85
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Comparing numpy float arrays in unit tests - python
I've tried unittest.assertEqual() but didn't work for float arrays because float are never 100% equal. I can't use assertAlmostEqual because it ...
Read more >numpy.allclose — NumPy v1.24 Manual
Returns True if two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference...
Read more >Python unittest - assertAlmostEqual() function - GeeksforGeeks
This function check that first and second are approximately equal by computing the difference, rounding to the given number of decimal places ( ......
Read more >API Reference — pytest documentation
Support for comparing sequences is provided by numpy.allclose() . ... Fixtures can provide their values to test functions using return or yield statements....
Read more >Guide to NumPy
an array scalar on item access but instead return the actual object ... The current chapter will provide background information.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ian-contiamo the ‘Open’ issue indicator is a good one!
assert_*_equal
already have thecheck_less_precise
kwarg so not sure this is necessary for testing functions. Would not be averse to adding aisclose=false
kwarg to.equals()
. This API needs to be fleshed out a bit.It seems like this change has not been made as of pandas 0.20.3: https://github.com/pandas-dev/pandas/blob/v0.20.3/pandas/core/generic.py#L865-L872
Did I miss something? Just as the OP, I think it would be nice to have access to
numpy.isclose
directly…