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

Pandas or Polars dataframes assert for equality with tolerance on float precision? #960

Closed
morindo opened this issue Feb 23, 2025 · 2 comments

Comments

@morindo
Copy link

morindo commented Feb 23, 2025

Is there a way to assert two Pandas or Polars dataframes for equality and have tolerance on float precision?

Right now when I save a Pandas dataframe as a snaphot using df.to_dict(), I'm able to compare actual and snapshot dataframes for equality on my Windows PC with success, but when I run pytest on a Linux machine, float columns are different and it fail the comparison due to float precision.

@noahnu
Copy link
Collaborator

noahnu commented Feb 24, 2025

I believe this is a duplicate of #913. Let me know if I've misinterpreted.

@morindo
Copy link
Author

morindo commented Feb 24, 2025

I confirm, the propose solution in syrupy v5 is working great!

def test_round_float(snapshot):
    assert (2.0 / 3.0) == snapshot(
        matcher=path_type(
            types=(float,), replacer=lambda data, _: round(data, 5)
        )
    )

@noahnu noahnu closed this as completed Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants