xarray icon indicating copy to clipboard operation
xarray copied to clipboard

Add a suite of property-based tests with Hypothesis

Open Zac-HD opened this issue 6 years ago • 3 comments

Hypothesis is a library for writing property-based tests in Python: you describe input data and make assertions that should be true for all examples, then Hypothesis tries to find a counterexample. This came up in #1840, because data == decode(encode(data)) is a classic property.

We could add a (initially small) suite of property-based tests, to complement the traditional example-based tests Xarray is already using. Keeping them in independent files will ensure that they run in CI but the dependency on Hypothesis remains optional for local development.

I have moved jobs and don't have time to do this myself, but I'd be very happy to help anyone who does 😄

Zac-HD avatar Jan 21 '18 03:01 Zac-HD

Reopening this issue as there is still a list of possible TODOs, as per @shoyer comment:

  • [ ] Consistency with pandas for groupby/rolling aggregations.
  • [ ] Roundtrip writing/reading data to netCDF. There are a couple of known exceptions (e.g., dtypes not supported by netCDF and MultiIndex) but otherwise every xarray object should be serializable to netCDF and back without data loss.
  • [ ] Roundtrip to/from pandas Series/DataFrame with to_series()/to_dataframe()/to_xarray().
  • [ ] Indexing consistency tests for backends: all indexing operations should be supported consistently on data accessed from any backend.
  • [ ] NumPy vs Dask: any operation on dask arrays should be consistent with the operation on numpy arrays (e.g., f(xarray_obj.chunk()).compute() == f(xarray_obj)).
  • [ ] Indexing followed by xarray.concat: should get back the same result.
  • [ ] Binary arithmetic on xarray objects with Python operators (+, -, etc) and NumPy ufuncs (np.add, np.subtract, etc).

fmaussion avatar Mar 20 '18 12:03 fmaussion

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

stale[bot] avatar Feb 18 '20 13:02 stale[bot]

@rdturnermtl wrote a Hypothesis extension for Xarray, which is at least a nice demo of what's possible.

If Xarray contributors want to keep working on this (#3283 seems stalled?) I'd be happy to help, since I'm both invested in Xarray working and would like to ship a hypothesis.extra.xarray some day :slightly_smiling_face:

Zac-HD avatar Apr 21 '20 05:04 Zac-HD