|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """Property tests comparing RasterIndex with PandasIndex for indexing operations.""" |
3 | 3 |
|
4 | | -from collections.abc import Hashable |
5 | | - |
6 | 4 | import numpy as np |
7 | 5 | import pytest |
8 | 6 | import xarray as xr |
|
23 | 21 | ) |
24 | 22 |
|
25 | 23 |
|
26 | | -def is_mixed_scalar_slice_indexer(indexers: dict[Hashable, int | slice]) -> bool: |
27 | | - # TODO: Fix bug in RasterIndex with mixed scalar/slice indexing across dimensions |
28 | | - # When you have scalar indexing on one dimension (e.g., y=0) and slice indexing |
29 | | - # on another (e.g., x=slice(None, 1)), RasterIndex.isel() returns None for the |
30 | | - # scalar dimension, dropping that index. This causes xarray to incorrectly handle |
31 | | - # the coordinate variables - the sliced dimension's coordinate (x) maintains |
32 | | - # dims ('x',) even though the data has been reduced by the scalar indexing. |
33 | | - # This results in: "ValueError: dimensions ('x',) must have the same length as |
34 | | - # the number of data dimensions, ndim=0" |
35 | | - # |
36 | | - # Example failing case: raster_da.isel(y=0, x=slice(None, 1)) |
37 | | - # - y=0 causes RasterIndex to return None for y dimension |
38 | | - # - x=slice(None, 1) preserves RasterIndex for x dimension |
39 | | - # - Result: coordinate variable x has wrong dimensionality |
40 | | - # |
41 | | - # For now, filter out these cases using hypothesis.assume() |
42 | | - has_scalar = any(isinstance(v, int | np.integer) for v in indexers.values()) |
43 | | - has_slice = any(isinstance(v, slice) for v in indexers.values()) |
44 | | - return has_scalar and has_slice and len(indexers) > 1 |
45 | | - |
46 | | - |
47 | 24 | @pytest.fixture |
48 | 25 | def raster_da(): |
49 | 26 | """Create a DataArray with RasterIndex coordinates.""" |
@@ -92,9 +69,7 @@ def pandas_da(raster_da): |
92 | 69 | def test_isel_basic_indexing_equivalence(data, raster_da, pandas_da): |
93 | 70 | """Test that isel produces identical results for RasterIndex and PandasIndex.""" |
94 | 71 | sizes = dict(raster_da.sizes) |
95 | | - indexers = data.draw( |
96 | | - basic_indexers(sizes=sizes).filter(lambda idxr: not is_mixed_scalar_slice_indexer(idxr)) |
97 | | - ) |
| 72 | + indexers = data.draw(basic_indexers(sizes=sizes)) |
98 | 73 | result_raster = raster_da.isel(indexers) |
99 | 74 | result_pandas = pandas_da.isel(indexers) |
100 | 75 | xr.testing.assert_identical(result_raster, result_pandas) |
|
0 commit comments