Closed jorisvandenbossche closed 1 year ago
Thanks for the detailed report. It's possible to change this on the GEOS side, but...is it desirable? The warning on construction strikes me as appropriate. Even though it's referring to FE_INVALID
, it's true that the constructed geometry is not considered valid by GEOS.
Yeah, I'd expect NaN to cause warnings in FP operations? Seems quite reasonable. Where does this NaN come from? At some point, you're just chasing gremlins and elves. Yes you can create a synthetic test case that raises warnings, but maybe a better thing would be not to construct geometries with NaN in them if that bothers you. In the limit, we could just disallow geometry construction with NaN/Inf coordinates, since what are we going to do with them?
Where does this NaN come from?
From creating some geometries manually with NaNs on purpose in the test suite ;) But yes, fully agreed that in this case the warning is totally expected (and so we are now also suppressing those warnings specifically for those tests, all good)
In shapely we are indeed thinking to disallow constructing geometries with NaNs, or at least to raise by default (so users are aware they are doing something they probably don't want or didn't intend) with potentially an option to force to create it with NaNs.
Seeing this in the shapely test suite using GEOS main, translated to a test case for GEOS (eg in
tests/unit/capi/GEOSLineStringTest.cpp
):This fails because the creation of a geometry with NaN coordinates now raises an "invalid" floating point exception, starting somewhere in the last two weeks. My first guess is that it is related to the envelope changes (https://github.com/libgeos/geos/commit/62edc7f05d44e83c1e70e1bf4e7f91738061d982, cc @dbaston), and a backtrace (if I add
feenableexcept(FE_INVALID);
to the test above) seems to confirm that;Now, of course this is a case where we have actual NaNs in the coordinates (in contrast to previous reported issues and PRs that fixed such FE exceptions for other cases), and so it might be decided this is fine to get a warning in this case.
What actually changed is the timing of the exception. Now it is already raised upon construction, while before it was when calculating the envelope. For example, testing with GEOS main from before the mentioned commit:
while with latest main:
So while finalizing writing this issue, I realize that the outcome is potentially that this is fine and nothing needs to be done. But since I now wrote it, opening it anyway ;)
(and the test failures on the shapely side are easy to solve, we just have to suppress the warnings when creating the test geometry with NaNs)