Uh oh!
There was an error while loading. Please reload this page.
Detailed report for testing.assert_equal and testing.assert_identical - #1507
Conversation
There was a problem hiding this comment.
I'm fine adding something like this. Another option would be to add a verbose repr that prints value, attributes, and encoding. This could be tacked on to .info() or a new method. Currently, this is designed to look like the output from the ncdump command line utility.
| assert a.identical(b), ( | ||
| '{}\n{}\n---\n{}\n{}' | ||
| .format(a, b, _get_info_as_str(a), _get_info_as_str(b)) | ||
| ) |
There was a problem hiding this comment.
if this is a xr.Variable instance, this will not work since it won't have the info method.
shoyer
commented
Aug 11, 2017
This is certainly welcome. In an ideal world, we might point specifically to the exact differing variables/attributes, but this is a fine start. |
benbovy
commented
Aug 11, 2017
Indeed, exact differing variables/attributes would be much better here. I'll look into this next week. pytest's failure reports and reports of |
max-sixty
commented
Jan 14, 2019
Any interest in pushing this over the line @benbovy ? |
4298eba to
53f80b3Comparebenbovy
commented
Jan 15, 2019
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 As examples: 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'})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'})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 |
Uh oh!
There was an error while loading. Please reload this page.
max-sixty
commented
Jan 15, 2019
i.e. there's a performance cost? Yeah that's def fine! |
max-sixty
commented
Jan 15, 2019
This looks amazing! I'm excited to use it. Thanks for finishing it up |
max-sixty
commented
Jan 15, 2019
If you want to add that example as a test, that could be a good way of documenting the function. But I don't think it's strictly needed |
benbovy
commented
Jan 15, 2019
I'm wondering which is the best among the options below: A. B. C. |
benbovy
commented
Jan 15, 2019
Yes I could use those examples for the tests. I think it might be good to write shallow tests at least for |
max-sixty
commented
Jan 15, 2019
I think you should feel free to merge an MVP rather than perfecting, but check out https://docs.pytest.org/en/latest/example/simple.html#writing-well-integrated-assertion-helpers I think that might be as simple as wrapping these in |
max-sixty
commented
Jan 15, 2019
TBH I think they're all good; I don't have a strong view. I'd low-confidence rank A->C->B |
dcherian
commented
Jan 15, 2019
I agree with @max-sixty A > C > B but only weakly. |
Hello @benbovy! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on January 16, 2019 at 13:27 Hours UTC |
max-sixty
commented
Jan 16, 2019
This looks v good @benbovy! |
benbovy
commented
Jan 16, 2019
Same opinion.
I'm just fixing |
| Differing coordinates: | ||
| L * x (x) <U1 'a' 'b' | ||
| R * x (x) <U1 'a' 'c' | ||
| Left contains more coordinates: |
There was a problem hiding this comment.
"Left contains more coordinates" sounds a little funny to me.
Maybe "Coordinates on the left DataArray but not the right" or "Coordinates only on the left object"?
There was a problem hiding this comment.
Agreed! I followed pytest's reports too blindly here.
benbovy
commented
Jan 18, 2019
If everyone is happy with this I'm going to merge it. |
shoyer
commented
Jan 18, 2019
Yes, please! |
max-sixty
commented
Jan 18, 2019
Thanks @benbovy! |
* master: stale requires a label (pydata#2701) Update indexing.rst (pydata#2700) add line break to message posted (pydata#2698) Config for closing stale issues (pydata#2684) to_dict without data (pydata#2659) Update asv.conf.json (pydata#2693) try no rasterio in py36 env (pydata#2691) Detailed report for testing.assert_equal and testing.assert_identical (pydata#1507) Hotfix for pydata#2662 (pydata#2678) Update README.rst (pydata#2682) Fix test failures with numpy=1.16 (pydata#2675)
* refactor-plot-utils: (22 commits) review comment. small rename stale requires a label (pydata#2701) Update indexing.rst (pydata#2700) add line break to message posted (pydata#2698) Config for closing stale issues (pydata#2684) to_dict without data (pydata#2659) Update asv.conf.json (pydata#2693) try no rasterio in py36 env (pydata#2691) Detailed report for testing.assert_equal and testing.assert_identical (pydata#1507) Hotfix for pydata#2662 (pydata#2678) Update README.rst (pydata#2682) Fix test failures with numpy=1.16 (pydata#2675) lint Back to map_dataarray_line Refactor out cmap_params, cbar_kwargs processing Refactor out colorbar making to plot.utils._add_colorbar flake8 facetgrid refactor Refactor out utility functions. ...
Closes #xxxxgit diff upstream/master | flake8 --diffwhats-new.rstfor all changes andapi.rstfor new APIIn addition toDatasetrepr, the error message also shows the output ofDataset.info()for both datasets.This may not be the most elegant solution, but it is helpful when datasets only differ by their attributes attached to coordinates or data variables (not shown in repr). I'm open to any suggestion.The report shows the differences for dimensions, data values (
VariableandDataArray), coordinates, data variables and attributes (the latter only fortesting.assert_identical).There is currently not much tests for
xarray.testingfunctions, but I'm willing to add more if needed.Not sure if it's worth a what's new entry (EDIT: added one).