-
Notifications
You must be signed in to change notification settings - Fork 45
Avoid calling hh.arrays with dtype=None for complex types #313
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
Avoid calling hh.arrays with dtype=None for complex types #313
Conversation
Does using pytest.skip not work here? That would be preferred if it can work. |
You could also try modifying hh.arrays so that it fails at example draw time instead of at function call time when dtypes=(). I'm curious how this is able to work when complex dtypes aren't enabled due to older standard versions. Maybe that isn't ever actually tested anywhere, since even array-api-strict's older standard flags doesn't actually support versions prior to adding complex support. We definitely do want to support skipping complex dtypes with ARRAY_API_TESTS_SKIP_DTYPES, but that hasn't been tested before. |
Apologies for the late reply!
I'm not sure how we may use
Might you have an example where something like that is already done in this project? I'm rather inexperienced with hypothesis. |
523bf4c
to
c43c83a
Compare
After digging a bit into the hypothesis documentation it seems that using the |
How does this look to you, @asmeurer ? |
@ev-br do you have feedback on this PR? |
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.
TIL about a pretty arcane hypothesis feature, as in, the nothing
strategy. Wow.
The PR looks good to me, merging.
Sorry @cbourjau it took us this long.
|
||
def all_floating_dtypes() -> SearchStrategy[DataType]: | ||
strat = floating_dtypes | ||
if api_version >= "2022.12" and complex_dtypes is not None: | ||
if api_version >= "2022.12" and not complex_dtypes.is_empty: |
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.
For the record, is_empty
here and below relies on the following:
In [16]: sampled_from([1, 2, 3]).is_empty
Out[16]: False
In [17]: nothing().is_empty
Out[17]: True
Issue description
ndonnx does not (yet) support complex data types. We signal that by setting
ARRAY_API_TESTS_SKIP_DTYPES="complex64,complex128"
. During the collection phasehypothesis_helpers.complex_dtypes
is set toNone
. However, downstream calls tohypothesis_helpers.arrays
appear to not be able to handledtype=None
as an argument, ultimately leading to an error when looking up the data type such as:Since data types are looked up using
__eq__
things appear to work if any of the data types compare equal toNone
which is the case fornumpy.dtype("float64")
, for example.Solution
This PR simply guards each affected tests (i.e. tests that work on
hypothesis_helpers.complex_dtypes
) with a respective if statement. This works just fine in practice for us, but I'm sure there is a better fix out there. I tried to setcomplex_dtypes = ()
, which seems reasonable, but that lead to other errors.