Fix test failure with GEOS 3.15. - #746
Conversation
The starting vertex of polygon boundaries returned by GEOS intersection is not guaranteed and shifted in GEOS 3.15.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #746 +/- ##
==========================================
- Coverage 93.68% 93.68% -0.01%
==========================================
Files 89 89
Lines 13715 13721 +6
==========================================
+ Hits 12849 12854 +5
- Misses 866 867 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
djhoese
left a comment
There was a problem hiding this comment.
Wow thanks for the fix. I had a couple questions about the new way of checking.
| for k in range(len(desired)): | ||
| if np.allclose(actual, np.roll(desired, k, axis=0), **kwargs): | ||
| return | ||
| np.testing.assert_allclose(actual, desired, **kwargs) |
There was a problem hiding this comment.
What does this check do that the np.allclose check doesn't cover?
|
|
||
| def _assert_ring_allclose(actual, desired, **kwargs): | ||
| for k in range(len(desired)): | ||
| if np.allclose(actual, np.roll(desired, k, axis=0), **kwargs): |
There was a problem hiding this comment.
Could this be np.testing.assert_allclose?
There was a problem hiding this comment.
Note that allclose has more lenient tolerances (rtol=1e-5, atol=1e-08) versus assert_allclose (rtol=1e-7, atol=0) so these tests are much more accepting of incorrect values than they used to be.
Additionally, when we're comparing two sets of arrays (lons + lats or x + y) we're letting the k choice here go separately. That is, checking lons could have a k of 0 and lats could find a k of 2 (for example). Although unlikely to be a problem, this is another way in which the tests are less strict than before.
Lastly, I asked Claude AI to look at this and it pointed out that this way of doing this can also ignore the clockwise/counter-clockwise checks of the existing tests. That is, depending on the values, enough rolls can result in an array that is equal to the reversal of an array. This is less likely if the k is shared between the two coordinates, but the last check changed in this PR doesn't check the lats so there's still a chance there. We do have some test utilities for checking CW/CCW which should maybe be added. test/test_geometry/test_swath_boundary.py should have _is_clockwise(lons, lats).
There was a problem hiding this comment.
Perhaps these tests should just be skipped with GEOS >= 3.15, unfortunately shapely.geos_version reports the build-time version of GEOS, not the runtime version.
CCing @maxyz as author of these changes. |
|
I was having trouble understanding how this would happen and the description that GEOS vertex order is no longer guaranteed. I asked Claude to take a look at the changelog and find the actual cause of all of this: I'll work on a fix and update your branch. No need to close this. |
|
I added the changes Claude suggested and updated the description with Claude's shortest summary of the problem. This would have been much simpler of shapely provided access to the libgeos version number but 🤷♂️ Thanks @sebastic for forwarding the patch on. |
New Description
Pyresample fails to build with GEOS 3.15 due to test failures as reported in Debian Bug #1146573.
get_geostationary_bounding_box_in_proj_coordsclips the geostationary disk against the area extentwith a shapely
Polygon.intersection, and the vertex GEOS starts the resulting ring at changed in3.15. Per the 3.15.0 release notes, under Breaking Changes:
So GEOS <= 3.14 was the anomaly, not 3.15: the expected arrays in
test_area_boundary.pywerecaptured against that spurious rotation, and on 3.15 the actual ring is
np.roll(expected, 1).Fixed by rotating both rings to a canonical starting vertex before comparing, so the tests pass on
either GEOS version. Vertex order, the pairing of the two coordinate arrays, winding direction and
the original tolerances all stay checked. A
shapely.geos_versioncheck would not work here — itreports the version shapely was built against, not the runtime library.
Original Description
Pyresample fails to build with GEOS 3.15 due to test failures as reported in Debian Bug #1146573.
The starting vertex of polygon boundaries returned by GEOS intersection is not guaranteed and shifted in GEOS 3.15.