home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 454496268

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/pull/1507#issuecomment-454496268 https://api.github.com/repos/pydata/xarray/issues/1507 454496268 MDEyOklzc3VlQ29tbWVudDQ1NDQ5NjI2OA== 4160723 2019-01-15T18:19:44Z 2019-01-15T18:19:44Z MEMBER

Thanks for reminding me this PR @max-sixty ! It deserves more than no commits since 1.5 years!

The assertion error messages now look like pytest's failure reports (see test_eq_dict). I've tried to reuse as much as possible the repr formatting that we already have for the xarray objects.

As examples:

```python ds_a = xr.Dataset(data_vars={'var1': (('x', 'y'), [[1, 2, 3], [4, 5, 7]]), 'var2': ('x', [3, 4])}, coords={'x': ['a', 'b'], 'y': [1, 2, 3]}, attrs={'units': 'm', 'description': 'desc'})

ds_b = xr.Dataset(data_vars={'var1': ('x', [1, 2])}, coords={'x': ('x', ['a', 'c'], {'source': 0}), 'label': ('x', [1, 2])}, attrs={'units': 'kg'})

xr.testing.assert_identical(ds_a, ds_b) AssertionError: Left and right Dataset objects are not identical Differing dimensions: (x: 2, y: 3) != (x: 2) Differing coordinates: L * x (x) <U1 'a' 'b' R * x (x) <U1 'a' 'c' source: 0 Left contains more coordinates: * y (y) int64 1 2 3 Right contains more coordinates: label (x) int64 1 2 Differing data variables: L var1 (x, y) int64 1 2 3 4 5 7 R var1 (x) int64 1 2 Left contains more data variables: var2 (x) int64 3 4 Differing attributes: L units: m R units: kg Left contains more attributes: description: desc ```

```python da_a = xr.DataArray([[1, 2, 3], [4, 5, 7]], dims=('x', 'y'), coords={'x': ['a', 'b'], 'y': [1, 2, 3]}, attrs={'units': 'm', 'description': 'desc'})

da_b = xr.DataArray([1, 2], dims='x', coords={'x': ['a', 'c'], 'label': ('x', [1, 2])}, attrs={'units': 'kg'})

xr.testing.assert_equal(da_a, da_b) AssertionError: Left and right DataArray objects are not equal Differing values: L array([[1, 2, 3], [4, 5, 7]]) R array([1, 2]) Differing coordinates: L * x (x) <U1 'a' 'b' R * x (x) <U1 'a' 'c' Left contains more coordinates: * y (y) int64 1 2 3 Right contains more coordinates: label (x) int64 1 2 ```

Those examples are probably not the most readable ones but it's for a full showcase.

A downside of this approach (i.e., report the exact differing) is that when a and b differs, full comparison is done once again for formatting the report. I don't think there is an easy way to avoid that, but I don't think it's a big deal either.

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  249584098
Powered by Datasette · Queries took 0.774ms · About: xarray-datasette