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

How to use Syrupy to save custom objects without converting them to strings #786

Closed
atharva-2001 opened this issue Aug 16, 2023 · 4 comments · Fixed by #789
Closed

How to use Syrupy to save custom objects without converting them to strings #786

atharva-2001 opened this issue Aug 16, 2023 · 4 comments · Fixed by #789

Comments

@atharva-2001
Copy link
Contributor

Dear Syrupy Team,
Thank you for this great package. I wanted to extend the SingleFileSnapshotExtension to save Pandas and NumPy objects to HDF files and .dat files respectively. I used the functions that you mentioned could be overridden(except the serialize function) to save these files in these new formats. However this specific line in get_assert_diff is causing an error that I just can't get past.

Both Dataframes and Arrays have no bool values, which is why doing something like dataframe or "" raises a ValueError.

Any help on how I can get past this error? Am I doing the wrong thing?
Here are a few references-
image

Here is the extension that I wrote-
https://github.com/atharva-2001/syrupy-pandas-numpy/blob/main/tests/test_pd.py

@noahnu
Copy link
Collaborator

noahnu commented Aug 16, 2023

That line can be updated to do an explicit "None" check. Are you interested in contributing / opening a PR?

@atharva-2001
Copy link
Contributor Author

Yes I would be very happy to! I would open a PR in sometime today!

@atharva-2001
Copy link
Contributor Author

@noahnu Would you mind looking at #789? Is the change alright? Also could you please review my code a bit as well? Is it safe to extend the class in the way I did from a sustainability perspective?

We are planning to add this library for our tests in TARDIS- https://tardis-sn.github.io/, https://github.com/tardis-sn and might be doing this across several repos.

Could the classes I made stay as is for at least 3-4 years?

@noahnu
Copy link
Collaborator

noahnu commented Aug 17, 2023

Yes the API you're using is stable. I was thinking about renaming some of the methods to remove the underscore, however I have no immediate plans to do so, and if that happens, it'd be in a new major version with a migration guide.

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

Successfully merging a pull request may close this issue.

2 participants