Skip to content

fix: Allow image coordinate irregularity equal to the tolerance#6915

Merged
hoxbro merged 3 commits into
holoviz:mainfrom
stanwest:image_datetime_rtol_warning
Jun 24, 2026
Merged

fix: Allow image coordinate irregularity equal to the tolerance#6915
hoxbro merged 3 commits into
holoviz:mainfrom
stanwest:image_datetime_rtol_warning

Conversation

@stanwest

Copy link
Copy Markdown
Contributor

Description

The change prevents an erroneous warning such as the following for regular date-time coordinates whose minimum step has coarse granularity in the internal date-time representation:

WARNING:param.Image00855: Image dimension x is not evenly sampled to relative tolerance of 0.001. Please use the QuadMesh element for irregularly sampled data or set a higher tolerance on hv.config.image_rtol or the rtol parameter in the Image constructor.

For such a step, the right-hand side of the inequality in holoviews.core.util.validate_regular_sampling can evaluate to a time delta of zero (depending on how the time-delta object rounds when multiplied), and the former < inequality cannot be satisfied. Also, the change conforms the function to its docstring ("at most") and to the documentation of Config.image_rtol ("maximal allowable sampling difference").

Fixes #6914.

Checklist

  • Pull request title follows the conventional format
  • Tests added and are passing

stanwest added 2 commits June 12, 2026 09:45
The expected failure is because of erroneous warning for regular
coordinates with coarse granularity within the spacing.
The change prevents an erroneous warning for regular date-time
coordinates whose minimum step has coarse granularity in the internal
date-time representation.  For such a step, the right-hand side can
evaluate to a time delta of zero (depending on how the object rounds
when multiplied), and the former `<` inequality cannot be satisfied.
Also, the change conforms the function to its docstring ("at most") and
to the documentation of `Config.image_rtol` ("maximal allowable sampling
difference").
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.32%. Comparing base (409699b) to head (ade0ed3).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6915      +/-   ##
==========================================
+ Coverage   89.29%   89.32%   +0.02%     
==========================================
  Files         344      344              
  Lines       74554    74577      +23     
==========================================
+ Hits        66573    66613      +40     
+ Misses       7981     7964      -17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hoxbro hoxbro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to verify with you that the tests fails without the suggested change.

Also have you been used AI for these changes?

Comment on lines +91 to +95
"""
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`.
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""
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`.
"""

Docstrings is not needed for tests.

Copy link
Copy Markdown
Contributor Author

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 of image_rtol. Would a comment be preferred over a docstring?

Comment on lines +117 to +123
"""
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`).
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""
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 +107 to +109
# |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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you choose two different ratios?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because datetime.timedelta and np.timedelta64 instances round differently when multiplied by a float such as image_rtol, the range of coordinate steps that will cause the false warning differs for the two types. (A datetime.timedelta instance rounds to the nearest microseconds, whereas a np.timedelta64 truncates toward zero.) Specifically, with image_rtol = 0.001, the false warning occurs for datetime.datetime steps of less than 500 microseconds and for np.datetime64 steps of less than 1000 units. For each type, I chose a step that is a little smaller than the largest sufficient step for that type.

@stanwest

Copy link
Copy Markdown
Contributor Author

Just want to verify with you that the tests fails without the suggested change.

One of the added tests, namely test_image_datetime_rtol_granularity, covers the buggy behavior and does fail without the change. (The first of the two commits decorates the test with pytest.mark.xfail so that the test suite passes, then the second commit, which contains the fix, removes the decorator.) The other added test covers the desirable warning behavior and passes in both commits.

Also have you been used AI for these changes?

I used no AI.

@hoxbro
hoxbro merged commit 2134030 into holoviz:main Jun 24, 2026
17 checks passed
hoxbro added a commit that referenced this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image with a regularly sampled date–time coordinate warns of irregular sampling when the spacing is less than 1000 date–time units

2 participants