-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Detailed report for testing.assert_equal and testing.assert_identical #1507
Conversation
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.
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.
xarray/testing.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is a xr.Variable
instance, this will not work since it won't have the info method.
This is certainly welcome. In an ideal world, we might point specifically to the exact differing variables/attributes, but this is a fine start. |
Indeed, exact differing variables/attributes would be much better here. I'll look into this next week. pytest's failure reports and reports of |
Any interest in pushing this over the line @benbovy ? |
4298eba
to
53f80b3
Compare
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 |
i.e. there's a performance cost? Yeah that's def fine! |
This looks amazing! I'm excited to use it. Thanks for finishing it up |
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 |
I'm wondering which is the best among the options below: A.
B.
C.
|
Yes I could use those examples for the tests. I think it might be good to write shallow tests at least for |
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 |
TBH I think they're all good; I don't have a strong view. I'd low-confidence rank A->C->B |
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 |
This looks v good @benbovy! |
Same opinion.
I'm just fixing |
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.
This looks fantastic!
xarray/tests/test_formatting.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! I followed pytest's reports too blindly here.
If everyone is happy with this I'm going to merge it. |
Yes, please! |
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 --diff
whats-new.rst
for all changes andapi.rst
for new APIIn addition toDataset
repr, 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 (
Variable
andDataArray
), coordinates, data variables and attributes (the latter only fortesting.assert_identical
).There is currently not much tests for
xarray.testing
functions, but I'm willing to add more if needed.Not sure if it's worth a what's new entry (EDIT: added one).