MCPcopy
hub / github.com/pydata/xarray / test_range_index_equals_exact

Function test_range_index_equals_exact

xarray/tests/test_range_index.py:370–389  ·  view source on GitHub ↗

Test that equals(exact=True) requires exact floating point match.

()

Source from the content-addressed store, hash-verified

368
369
370def 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)

Callers

nothing calls this directly

Calls 4

iselMethod · 0.95
arangeMethod · 0.80
from_xindexMethod · 0.80
equalsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…