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

[Feature Request] support Pandas Dataframe #167

Open
xareelee opened this issue May 19, 2023 · 2 comments
Open

[Feature Request] support Pandas Dataframe #167

xareelee opened this issue May 19, 2023 · 2 comments

Comments

@xareelee
Copy link

Is that possible to support Pandas Dataframe?

Currently, snapshottest only translate df into GenericRepr string value. The detailed data will be abbreviated.

I hope it can put the dataframe into csv like format, and compare them row by row.

@Girmii
Copy link

Girmii commented Oct 31, 2024

A possible quick fix is to convert the DataFrame to CSV before passing it to snapshottest;

snapshot.assert_match(df.to_csv(index=False), "snapshot_name")

The main downside is that if the assert fails, the error will concern the difference in string values of the CSVs and not those of the actual DataFrames. Additionally, the index cannot be verified.

@Girmii
Copy link

Girmii commented Oct 31, 2024

Alternatively, look at the following extension, which automatically serializes/deserializes the DataFrame and performs the comparison with the pandas assert_frame_equal function;
https://github.com/swuecho/snapshottest_ext/blob/master/snapshottest_ext/dataframe.py

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