Skip to content

Commit

Permalink
Close Bears-R-Us#2871: Fix numeric precision issue in testHistogram (
Browse files Browse the repository at this point in the history
…Bears-R-Us#2872)

This PR (closes Bears-R-Us#2871) change list equals to np.allclose to avoid numeric precision issues

Co-authored-by: Pierce Hayes <[email protected]>
  • Loading branch information
stress-tess and Pierce Hayes authored Dec 5, 2023
1 parent 4d61414 commit c383013
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/numeric_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def testHistogram(self):
self.assertEqual(20, len(ak_bins) - 1)
self.assertEqual(20, len(ak_result))
self.assertEqual(int, ak_result.dtype)
self.assertListEqual(ak_result.to_list(), np_result.tolist())
self.assertListEqual(ak_bins.to_list(), np_bins.tolist())
self.assertTrue(np.allclose(ak_result.to_list(), np_result.tolist()))
self.assertTrue(np.allclose(ak_bins.to_list(), np_bins.tolist()))

with self.assertRaises(TypeError):
ak.histogram([range(0, 10)], bins=1)
Expand All @@ -153,15 +153,15 @@ def testHistogram(self):
np_x, np_y = ak_x.to_ndarray(), ak_y.to_ndarray()
np_hist, np_x_edges, np_y_edges = np.histogram2d(np_x, np_y)
ak_hist, ak_x_edges, ak_y_edges = ak.histogram2d(ak_x, ak_y)
self.assertListEqual(np_hist.tolist(), ak_hist.to_list())
self.assertListEqual(np_x_edges.tolist(), ak_x_edges.to_list())
self.assertListEqual(np_y_edges.tolist(), ak_y_edges.to_list())
self.assertTrue(np.allclose(np_hist.tolist(), ak_hist.to_list()))
self.assertTrue(np.allclose(np_x_edges.tolist(), ak_x_edges.to_list()))
self.assertTrue(np.allclose(np_y_edges.tolist(), ak_y_edges.to_list()))

np_hist, np_x_edges, np_y_edges = np.histogram2d(np_x, np_y, bins=(10, 20))
ak_hist, ak_x_edges, ak_y_edges = ak.histogram2d(ak_x, ak_y, bins=(10, 20))
self.assertListEqual(np_hist.tolist(), ak_hist.to_list())
self.assertListEqual(np_x_edges.tolist(), ak_x_edges.to_list())
self.assertListEqual(np_y_edges.tolist(), ak_y_edges.to_list())
self.assertTrue(np.allclose(np_hist.tolist(), ak_hist.to_list()))
self.assertTrue(np.allclose(np_x_edges.tolist(), ak_x_edges.to_list()))
self.assertTrue(np.allclose(np_y_edges.tolist(), ak_y_edges.to_list()))

def testLog(self):
na = np.linspace(1, 10, 10)
Expand Down

0 comments on commit c383013

Please sign in to comment.