Skip to content

BUG: tm.assert_frame_equal fails to raise near int64 implementation bounds when check_exact=True #40719

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

Open
jbrockmendel opened this issue Apr 1, 2021 · 5 comments
Labels
Bug Testing pandas testing functions or related to the test suite

Comments

@jbrockmendel
Copy link
Member

passing check_exact=True makes it raise as expected, but I was surprised to find it necessary. This likely hides some bugs.

Motivating example adapted from tests.groupby.test_function.test_cummin.

dtype = np.dtype(np.int64)
min_val = np.iinfo(dtype).min

base_df = DataFrame({"A": [1, 1, 1, 1, 2, 2, 2, 2], "B": [3, 4, 3, 2, 2, 3, 2, 1]})
expected_mins = [3, 3, 3, 2, 2, 2, 2, 1]
expected = DataFrame({"B": expected_mins}).astype(dtype)

df = base_df.astype(dtype)

# Test w/ min value for dtype
df.loc[[2, 6], "B"] = min_val
df.loc[[1, 5], "B"] = min_val + 1
result = df.groupby("A").cummin()

expected.loc[[1, 5], "B"] = min_val + 1
expected.loc[[2, 3, 6, 7], "B"] = min_val

tm.assert_frame_equal(result, expected)  #  <-- passes
tm.assert_frame_equal(result, expected, check_exact=True)  # <-- raises


>>> result
                     B
0                    3
1 -9223372036854775808
2 -9223372036854775808
3 -9223372036854775808
4                    2
5 -9223372036854775808
6 -9223372036854775808
7 -9223372036854775808

>>> expected
                     B
0                    3
1 -9223372036854775807
2 -9223372036854775808
3 -9223372036854775808
4                    2
5 -9223372036854775807
6 -9223372036854775808
7 -9223372036854775808

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 1, 2021
@mzeitlin11
Copy link
Member

This ends up falling down to using math.isclose with tolerances large enough that these compare as equal. I'm guessing the default of comparison with tolerance is just to avoid floating point comparison problems. Seems like ints should just always be given an exact comparison by default?

@mzeitlin11 mzeitlin11 added Testing pandas testing functions or related to the test suite and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 3, 2021
@jbrockmendel
Copy link
Member Author

Seems like ints should just always be given an exact comparison by default?

thats my thought too

@mzeitlin11
Copy link
Member

@jbrockmendel how public are these functions (eg can we just change the default for integer data to check_exact=True or do we have to worry about backwards compat?) Also xref #30347

@jbrockmendel
Copy link
Member Author

in the past when ive changed tm.assert_foo functions @jorisvandenbossche eventually reports that a downstream package has been affectd

@topper-123
Copy link
Contributor

IMO the check_exact param should only apply to floats, i.e. the example in OP should fail. I also think this is a bug, i.e. we can fix just this without deprecation.

@topper-123 topper-123 changed the title BUG: tm.assert_frame_equal fails to raise near int64 implementation bounds BUG: tm.assert_frame_equal fails to raise near int64 implementation bounds when check_exact=True May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

3 participants