Skip to content

Do not use strict equality for bouning boxes comparison - #247

Merged
vincentsarago merged 1 commit into
developmentseed:mainfrom
avalentino:bugfix/no-strict-equality
Sep 1, 2026
Merged

Do not use strict equality for bouning boxes comparison#247
vincentsarago merged 1 commit into
developmentseed:mainfrom
avalentino:bugfix/no-strict-equality

Conversation

@avalentino

Copy link
Copy Markdown
Contributor

Without the change, test_tiles_when_tms_bounds_and_provided_bounds_cross_antimeridian fails on Debian Sid x86_64 as reported below.

The reason is that floating point numbers are not exactly equal but the relative error is really low and the test indeed already foresees a comparison of coordinates up to the 6th decimal digit, but is fails because of a strict equality comparison on the bbox tuples.

$ python3 -m pytest 
================================================================================ test session starts ================================================================================
platform linux -- Python 3.14.7, pytest-9.1.1, pluggy-1.6.0
benchmark: 5.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/antonio/debian/git/morecantile
configfile: pyproject.toml
plugins: typeguard-4.4.4, cov-7.1.0, anyio-4.12.1, hypothesis-6.155.7, mock-3.15.1, lazy-fixtures-0.0.0, asyncio-1.4.0, zarr-3.3.0, recording-0.13.4, benchmark-5.2.3, xdist-3.8.0, requests_mock-1.12.1
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 277 items                                                                                                                                                                 

tests/test_cli.py ............                                                                                                                                                [  4%]
tests/test_mercantile_conform.py ........................................                                                                                                     [ 18%]
tests/test_models.py ............................................................................................................................................             [ 69%]
tests/test_morecantile.py ......................xx.x......................F.........................                                                                          [ 96%]
tests/test_tms_variable_width.py ...                                                                                                                                          [ 97%]
tests/test_utils.py ........                                                                                                                                                  [100%]

===================================================================================== FAILURES ======================================================================================
___________________________________________ test_tiles_when_tms_bounds_and_provided_bounds_cross_antimeridian[bounds1-4-32632-tms_bbox1] ____________________________________________

bounds = (11.700978, 52.056474, 11.711114, 52.062706), expected = 4, crs = 32632, tms_bbox = (-17.582877658817317, 0.0, 95.87417095917766, 83.95429547980198)

    @pytest.mark.parametrize(
        ("bounds", "expected", "crs", "tms_bbox"),
        [
            # case where east tms bbox crosses antimeridian
            (
                (119.1, -32.86, 119.2, -32.82),
                6,
                32750,
                (100.23646734667152, -79.99407435445299, -158.6052850376368, 0.0),
            ),
            # case where west tms bbox crosses antimeridian
            (
                (11.700978, 52.056474, 11.711114, 52.062706),
                4,
                32632,
                (-17.582877658817317, 0.0, 95.87417095917766, 83.95429547980198),
            ),
        ],
    )
    def test_tiles_when_tms_bounds_and_provided_bounds_cross_antimeridian(
        bounds: tuple, expected: int, crs: int, tms_bbox: tuple
    ):
        utm = CRS.from_epsg(crs)
        rs_extent = utm.area_of_use.bounds
        tms = morecantile.TileMatrixSet.custom(
            crs=utm, extent_crs=CRS.from_epsg(4326), extent=list(rs_extent)
        )
        # tms.tiles needs to be aware if tms bounds and input bounds crosses the
        # antimeridian e.g. min(119.2, -158.605) clamps to much larger area. Now
        # that we check to see if lons contain antimeridian, we build tiles that
        # actually overlap the provided bounds to tiles.
>       assert tms.bbox == tms_bbox
E       assert BoundingBox(l...5429547980198) == (-17.58287765...5429547980198)
E         
E         At index 0 diff: -17.582877658817313 != -17.582877658817317
E         Use -v to get more diff

tests/test_morecantile.py:457: AssertionError
================================================================================= warnings summary ==================================================================================
tests/test_morecantile.py::test_is_valid_overzoom
  /home/antonio/debian/git/morecantile/morecantile/models.py:842: UserWarning: TileMatrix not found for level: 25 - Creating values from TMS Scale.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================== short test summary info ==============================================================================
FAILED tests/test_morecantile.py::test_tiles_when_tms_bounds_and_provided_bounds_cross_antimeridian[bounds1-4-32632-tms_bbox1] - assert BoundingBox(l...5429547980198) == (-17.58287765...5429547980198)
================================================================ 1 failed, 273 passed, 3 xfailed, 1 warning in 1.55s ================================================================

@vincentsarago
vincentsarago merged commit 672ae89 into developmentseed:main Sep 1, 2026
5 checks passed
@avalentino

Copy link
Copy Markdown
Contributor Author

Thanks @vincentsarago

@avalentino
avalentino deleted the bugfix/no-strict-equality branch September 1, 2026 14:39
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.

2 participants