-
-
Notifications
You must be signed in to change notification settings - Fork 416
fix: Allow image coordinate irregularity equal to the tolerance #6915
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |||||||||||||||
|
|
||||||||||||||||
| from __future__ import annotations | ||||||||||||||||
|
|
||||||||||||||||
| import datetime as dt | ||||||||||||||||
|
|
||||||||||||||||
| import numpy as np | ||||||||||||||||
| import pytest | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -74,6 +76,55 @@ def test_image_rtol_config(self): | |||||||||||||||
| hv.Image({"vals": vals, "xs": xs, "ys": ys}, ["xs", "ys"], "vals") | ||||||||||||||||
| hv.config.image_rtol = image_rtol | ||||||||||||||||
|
|
||||||||||||||||
| @pytest.mark.parametrize( | ||||||||||||||||
| "x", | ||||||||||||||||
| [ | ||||||||||||||||
| # max(|step|) / min(|step|) - 1 = 0.0015 | ||||||||||||||||
| [dt.datetime(2017, 1, 1, 0, 0, 0, ms) for ms in [0, 10000, 20015]], | ||||||||||||||||
| *( | ||||||||||||||||
| np.array([0, 10000, 20015]).astype(f"datetime64[{unit}]") | ||||||||||||||||
| for unit in ["D", "h", "m", "s", "ms", "us"] | ||||||||||||||||
| ), | ||||||||||||||||
| ], | ||||||||||||||||
| ) | ||||||||||||||||
| def test_image_datetime_rtol_failure(self, x): | ||||||||||||||||
| """ | ||||||||||||||||
| Constructing an Image with a date-time coordinate warns about irregular sampling | ||||||||||||||||
| if, approximately speaking, one less than the ratio of the max and min steps | ||||||||||||||||
| exceeds the default `image_rtol`. | ||||||||||||||||
| """ | ||||||||||||||||
| y = np.arange(2) | ||||||||||||||||
| hv.Image((x, y, np.zeros((len(y), len(x))))) | ||||||||||||||||
| self.log_handler.assert_endswith( | ||||||||||||||||
| "WARNING", | ||||||||||||||||
| "set a higher tolerance on hv.config.image_rtol or the rtol parameter in " | ||||||||||||||||
| "the Image constructor.", | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| @pytest.mark.parametrize( | ||||||||||||||||
| "x", | ||||||||||||||||
| [ | ||||||||||||||||
| # |granularity / step| = 1/400 = 0.0025 | ||||||||||||||||
| [dt.datetime(2017, 1, 1, 0, 0, 0, ms) for ms in [0, 400]], | ||||||||||||||||
| # |granularity / step| = 1/800 = 0.00125 | ||||||||||||||||
|
Comment on lines
+107
to
+109
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you choose two different ratios?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because |
||||||||||||||||
| *( | ||||||||||||||||
| np.array([10000, 10800]).astype(f"datetime64[{unit}]") | ||||||||||||||||
| for unit in ["D", "h", "m", "s", "ms", "us"] | ||||||||||||||||
| ), | ||||||||||||||||
| ], | ||||||||||||||||
| ) | ||||||||||||||||
| def test_image_datetime_rtol_granularity(self, x): | ||||||||||||||||
| """ | ||||||||||||||||
| Constructing an Image with an evenly spaced date-time coordinate does not warn | ||||||||||||||||
| about irregular sampling, even when the ratio of the date-time granularity to | ||||||||||||||||
| the coordinate step is greater than the default `image_rtol` (or twice | ||||||||||||||||
| `image_rtol` for `datetime.datetime` types because of how they round when | ||||||||||||||||
| multiplied by a `float`). | ||||||||||||||||
| """ | ||||||||||||||||
|
Comment on lines
+117
to
+123
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| y = np.arange(2) | ||||||||||||||||
| hv.Image((x, y, np.zeros((len(y), len(x))))) | ||||||||||||||||
| assert len(self.log_handler.tail("WARNING", n=1)) == 0 | ||||||||||||||||
|
|
||||||||||||||||
| def test_image_clone(self): | ||||||||||||||||
| vals = np.random.rand(20, 20) | ||||||||||||||||
| xs = np.linspace(0, 10, 20) | ||||||||||||||||
|
|
||||||||||||||||
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.
Docstrings is not needed for tests.
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 understand. I see the docstring as a natural place to explain the intent of a non-obvious test. Here, in particular, it relates the test to
image_rtol, a relationship that isn't apparent from the test's parameters, which are declared independently ofimage_rtol. Would a comment be preferred over a docstring?