Skip to content
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

Change assert #712

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion invisible_cities/cities/beersheba_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_create_deconvolution_df(ICDATADIR):
CutType.abs, ecut, 3) for _, t in true_dst.groupby('event')])
true_dst = true_dst.loc[true_dst.E > ecut, :].reset_index(drop=True)

assert_dataframes_close(new_dst, true_dst)
assert_dataframes_close(new_dst .reset_index(drop=True), true_dst.reset_index(drop=True))


@mark.parametrize("cut_type", CutType.__members__)
Expand Down
4 changes: 3 additions & 1 deletion invisible_cities/cities/esmeralda_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def test_esmeralda_tracks_exact(data_hdst, esmeralda_tracks, correction_map_file
#some events are not in df_tracks_exact
events = df_tracks_exact.event.unique()
df_tracks_cut = df_tracks[df_tracks.event.isin(events)]
assert_dataframes_close (df_tracks_cut[columns2], df_tracks_exact[columns2])

assert_dataframes_close (df_tracks_cut[columns2] .reset_index(drop=True),
df_tracks_exact[columns2].reset_index(drop=True))
#make sure out_of_map is true for events not in df_tracks_exact
diff_events = list(set(df_tracks.event.unique()).difference(events))
df_summary = dio.load_dst(PATH_OUT, 'Summary', 'Events')
Expand Down
14 changes: 11 additions & 3 deletions invisible_cities/core/testing_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pandas as pd

from pytest import approx
from numpy.testing import assert_array_equal
Expand Down Expand Up @@ -106,11 +107,18 @@ def _compare_dataframes(assertion, df1, df2, check_types=True, **kwargs):


def assert_dataframes_equal(df1, df2, check_types=True, **kwargs):
_compare_dataframes(assert_array_equal, df1, df2, check_types, **kwargs)
pd.testing.assert_frame_equal(df1.sort_index(axis=1), df2.sort_index(axis=1), check_names=True, check_dtype=check_types, check_exact=True, **kwargs)

def assert_dataframes_close(df1, df2, check_types=True, rtol=None, atol=None, **kwargs):
if rtol:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can someone else also check this makes sense, @gonzaponte , @andLaing ?

check_less_precise = int(np.log10(1./rtol))
elif atol:
check_less_precise = int(np.log10(atol))
else:
check_less_precise = True

def assert_dataframes_close(df1, df2, check_types=True, **kwargs):
_compare_dataframes(assert_allclose, df1, df2, check_types, **kwargs)
pd.testing.assert_frame_equal(df1.sort_index(axis=1), df2.sort_index(axis=1),
check_names=True, check_dtype=check_types, check_less_precise = check_less_precise)


def assert_SensorResponses_equality(sr0, sr1):
Expand Down