Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Hypothesis tests for roundtrip to & from pandas #3285
Hypothesis tests for roundtrip to & from pandas #3285
Changes from 7 commits
1e8ac35
9f14426
18790cc
2449ac2
54900f0
02fd311
e8fb3da
67c7034
4ba4f7b
fb222c5
7b39a6f
a328739
3f462be
ecd016a
351b40b
044c67d
5b0ae82
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These may need to be guarded too using
pytest.importorskip
perhaps? @max-sixty what do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes same as here! https://github.com/max-sixty/xarray/blob/black/properties/test_encode_decode.py#L9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, I was being distracted by the other errors around the real one. Let's see if the latest commit helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern - draw a number, then draw that many elements - is tempting but tends to be inefficient when Hypothesis tries to minimse any failures.
The alternative, which we recommend, is to generate collections using the
st.lists()
strategy - that way Hypothesis will be able to operate in terms of elements of the list.In this case it's probably only worth doing so for either the vars or entries dimension, and keep the other as-is. If you're keen to do both, it's complicated enough that I'd just fall back on the Hypothesis pandas extension and
.map(pd.DataFrame.to_xarray)
over the result 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to do this, because in both dimension I want to generate multiple things of the same length - same number of names and arrays for the vars dimension, same number of entries in each array for the entries dimension. If I naively generate lists, they'll have different lengths.
Is it better to generate one such things with the lists strategy, and then make the others to match its length, rather than generating a number to use as the length for all of them? Or is there some overall cleverer way that I'm not seeing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could draw
indices
before the loop, then draw a list of (name, array) tuples. Or in this case you could usest.dictionaries()
to, well, generate a list of key-value tuples internally.The other nice trick would be to draw your index first, and use it's length - deleting elements from that will be slightly more efficient than shrinking the
n_elements
parameter.Putting it all togther, I'd write
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that does look neater!
This comment was marked as resolved.
Sorry, something went wrong.