Skip to content

TST: make the WKB test robust for flavour of NaN#1123

Closed
jorisvandenbossche wants to merge 14 commits intoshapely:shapely-2.0from
jorisvandenbossche:wkb-robust-nan
Closed

TST: make the WKB test robust for flavour of NaN#1123
jorisvandenbossche wants to merge 14 commits intoshapely:shapely-2.0from
jorisvandenbossche:wkb-robust-nan

Conversation

@jorisvandenbossche
Copy link
Copy Markdown
Member

This test_wkb.py::test_point_empty test is failing on the shapely-2.0 branch with the latest pygeos. I think this is because pygeos is using Py_NAN to write the WKB with NaN values for empty geometries, and Py_NAN might be platform-dependent (the error on appveyor indicates the WKB includes a negative quiet NaN (-float(NaN)) instead of a plain quiet NaN, by checking on my linux laptop).

So this PR tries to make the test more robust, by using the default NaN representation from the system on which the test is running (which should match with the NaN value that pygeos is using, I think).

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

cc @musicinmybrain does this look OK to ensure it still works on big-endian hosts as well?

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 9, 2021

Coverage Status

Coverage decreased (-0.05%) to 77.792% when pulling 56cea7e on jorisvandenbossche:wkb-robust-nan into 024f75a on Toblerity:shapely-2.0.

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

Hmm, that didn't actually help for windows. Trying the approach used in pygeos then to check the unpacked bytes with isnan

@musicinmybrain
Copy link
Copy Markdown
Contributor

cc @musicinmybrain does this look OK to ensure it still works on big-endian hosts as well?

The current code looks OK since it uses the big_endian=False option to shapely.wkb.dumps, so the resulting byte string should be little-endian regardless of the host endianness. The code also correctly uses '>' at the beginning of the struct.unpack format string to ensure the byte string is unpacked as little-endian.

I think that using math.isnan is a good approach. Except in the very rare cases where software actually uses the NaN “payload” bits to smuggle data around, there are too many ways that assuming a particular representation can go wrong.

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

Thanks! Yes, the final version that I pushed shouldn't be sensitive to little/big endian host anymore, since I force little_endian in the output. Of course that then also doesn't test the big endian is correct ..

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

The change from this PR is included in #1213, so closing this one.

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.

3 participants