holoviz / spatialpandas

Pandas extension arrays for spatial/geometric operations
BSD 2-Clause "Simplified" License
308 stars 24 forks source link

`test_triangle_orientation` fails intermittently #61

Closed brl0 closed 2 years ago

brl0 commented 3 years ago

The test below fails intermittently.

__________________________ test_triangle_orientation ___________________________

    @given(coord, coord, coord, coord, coord, coord)
>   @hyp_settings
    def test_triangle_orientation(ax, ay, bx, by, cx, cy):

spatialpandas/tests/geometry/algorithms/test_orientation.py:9: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

ax = 0.0, ay = -4.440892098500627e-13, bx = 6.661338147750941e-13
by = 2.2204460492503136e-13, cx = 4.440892098500627e-13, cy = 0.0

    @given(coord, coord, coord, coord, coord, coord)
    @hyp_settings
    def test_triangle_orientation(ax, ay, bx, by, cx, cy):
        result = triangle_orientation(ax, ay, bx, by, cx, cy)

        # Use shapely polygon to compute expected orientation
        sg_poly = sg.Polygon([(ax, ay), (bx, by), (cx, cy), (ax, ay)])

        if sg_poly.area == 0:
            expected = 0
        else:
            expected = 1 if sg_poly.exterior.is_ccw else -1

>       assert result == expected
E       assert 0 == 1
E         +0
E         -1

spatialpandas/tests/geometry/algorithms/test_orientation.py:21: AssertionError
---------------------------------- Hypothesis ----------------------------------
Falsifying example: test_triangle_orientation(
    ax=0.0,
    ay=-4.440892098500627e-13,
    bx=6.661338147750941e-13,
    by=2.2204460492503136e-13,
    cx=4.440892098500627e-13,
    cy=0.0,
)

You can reproduce this example by temporarily adding @reproduce_failure('6.1.1', b'AXicY2CAAEYIxQTlMqMKw8UZAAEIAAo=') as a decorator on your test case
ianthomas23 commented 2 years ago

This was fixed by #90 and there is an explanation written therein.

Essentially the geometry code is only robust to real-world size differences such as say 1 m over 1000 km, i.e. O(1e-6) differences. The CI was working down to O(1e-15) which will not give reliable results. So I have limited the precision of the geometry tests.