question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

assert_almost_equal / equals should allow access to np.allclose

See original GitHub issue

I 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:closed
  • Created 9 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jrebackcommented, Jul 10, 2017

@ian-contiamo the ‘Open’ issue indicator is a good one!

assert_*_equal already have the check_less_precise kwarg so not sure this is necessary for testing functions. Would not be averse to adding a isclose=false kwarg to .equals(). This API needs to be fleshed out a bit.

0reactions
ian-contiamocommented, Jul 10, 2017

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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found