Test that equals(exact=True) requires exact floating point match.
()
| 368 | |
| 369 | |
| 370 | def test_range_index_equals_exact() -> None: |
| 371 | """Test that equals(exact=True) requires exact floating point match.""" |
| 372 | # Create an index directly |
| 373 | index1 = RangeIndex.arange(0.0, 0.3, 0.1, dim="x") |
| 374 | |
| 375 | # Create the same index by slicing - this accumulates floating point error |
| 376 | index_large = RangeIndex.arange(0.0, 1.0, 0.1, dim="x") |
| 377 | ds_large = xr.Dataset(coords=xr.Coordinates.from_xindex(index_large)) |
| 378 | ds_sliced = ds_large.isel(x=slice(3)) |
| 379 | index2 = ds_sliced.xindexes["x"] |
| 380 | |
| 381 | # Default (exact=False) should be equal due to np.isclose tolerance |
| 382 | assert index1.equals(index2) |
| 383 | |
| 384 | # With exact=True, tiny floating point differences cause inequality |
| 385 | assert not index1.equals(index2, exact=True) |
| 386 | |
| 387 | # But identical indexes should still be equal with exact=True |
| 388 | index3 = RangeIndex.arange(0.0, 0.3, 0.1, dim="x") |
| 389 | assert index1.equals(index3, exact=True) |
nothing calls this directly
no test coverage detected
searching dependent graphs…