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

Automatic duck array testing - reductions #4972

Draft
wants to merge 140 commits into
base: main
Choose a base branch
from

Conversation

keewis
Copy link
Collaborator

@keewis keewis commented Feb 27, 2021

This is the first of a series of PRs to add a framework to make testing the integration of duck arrays as simple as possible. It uses hypothesis for increased coverage and maintainability.

  • Tests added
  • Passes pre-commit run --all-files
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

@TomNicholas
Copy link
Member

TomNicholas commented Aug 9, 2022

Q: Shouldn't the base classes live in xarray.testing rather than xarray.tests?

Then the test_units.py and test_sparse.py live in xarray.tests (until they eventually get moved to another repo), but import the base classes from xarray.tests?

def check_reduce(self, obj, op, *args, **kwargs):
actual = getattr(obj, op)(*args, **kwargs)

data = np.asarray(obj.data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename instances of arrays to be called arr instead of data? It took me a pretty long time to realise that this had nothing to do with hypothesis' strategies.data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, although it would probably be better to call it numpy_arr or move it into the .copy call

@TomNicholas
Copy link
Member

Q: Shouldn't the base classes live in xarray.testing rather than xarray.tests?

Another Q on a similar note: Are we planning to eventually publicly expose the (awesome btw) strategies that you've built here @keewis ? They could be very useful for testing other parts of xarray.

We could also make this PR much more incremental by splitting it into 2, or even 3 separate PRs:

  1. strategies, to live somewhere like xarray.testing.strategies and eventually be made public
  2. duck array base classes to inherit from, to live somewhere like xarray.testing.duckarrays
  3. specific tests for pint/sparse, to live in our own test suite for now but moved out eventually.

The advantage of that would be that (1) & (2) can move forwards without requiring all the tests in (3) to pass.

Copy link
Collaborator Author

@keewis keewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! This PR is just a prototype of how the testing framework could look like, I didn't really think about the structure yet. I also agree that both the strategies as well as the base classes should eventually live in xarray.testing, but I'd probably keep them in xarray.tests for now (just so we can experiment a bit more).

Note, however, that it's probably best not to separate 2 and 3 because there might be issues with the base class design we don't notice without trying to actually use them.

def check_reduce(self, obj, op, *args, **kwargs):
actual = getattr(obj, op)(*args, **kwargs)

data = np.asarray(obj.data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, although it would probably be better to call it numpy_arr or move it into the .copy call

xarray/tests/duckarrays/base/strategies.py Show resolved Hide resolved
@TomNicholas
Copy link
Member

I also agree that both the strategies as well as the base classes should eventually live in xarray.testing, but I'd probably keep them in xarray.tests for now (just so we can experiment a bit more).

So I may actually have overexcitedly already jumped the gun and made a PR to move strategies to xarray.testing.strategies last night 😅 #6908 We might just want to wait to merge this before merging that though anyway.

Note, however, that it's probably best not to separate 2 and 3 because there might be issues with the base class design we don't notice without trying to actually use them.

Good point.

@TomNicholas TomNicholas added topic-testing topic-arrays related to flexible array support topic-hypothesis Strategies or tests using the hypothesis library labels Aug 12, 2022
@keewis
Copy link
Collaborator Author

keewis commented Aug 16, 2022

We might just want to wait to merge this before merging that though anyway.

I actually think it should be the other way around: if we can get the strategies from #6908 to shrink well, we might be able to fix the occasional test timeouts here (which should be one of the final issues we have before we can merge this).

@TomNicholas
Copy link
Member

if we can get the strategies from #6908 to shrink well

I think they already do shrink well. Each of them has corresponding unit tests, and none of those tests fail due to hypothesis timeouts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-arrays related to flexible array support topic-hypothesis Strategies or tests using the hypothesis library topic-testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants