(self)
| 893 | assert_identical(expected, actual) |
| 894 | |
| 895 | def test_vectorized_indexing(self) -> None: |
| 896 | in_memory = create_test_data() |
| 897 | with self.roundtrip(in_memory) as on_disk: |
| 898 | indexers = { |
| 899 | "dim1": DataArray([0, 2, 0], dims="a"), |
| 900 | "dim2": DataArray([0, 2, 3], dims="a"), |
| 901 | } |
| 902 | expected = in_memory.isel(indexers) |
| 903 | actual = on_disk.isel(**indexers) |
| 904 | # make sure the array is not yet loaded into memory |
| 905 | assert not actual["var1"].variable._in_memory |
| 906 | assert_identical(expected, actual.load()) |
| 907 | # do it twice, to make sure we're switched from |
| 908 | # vectorized -> numpy when we cached the values |
| 909 | actual = on_disk.isel(**indexers) |
| 910 | assert_identical(expected, actual) |
| 911 | |
| 912 | def multiple_indexing(indexers): |
| 913 | # make sure a sequence of lazy indexings certainly works. |
| 914 | with self.roundtrip(in_memory) as on_disk: |
| 915 | actual = on_disk["var3"] |
| 916 | expected = in_memory["var3"] |
| 917 | for ind in indexers: |
| 918 | actual = actual.isel(ind) |
| 919 | expected = expected.isel(ind) |
| 920 | # make sure the array is not yet loaded into memory |
| 921 | assert not actual.variable._in_memory |
| 922 | assert_identical(expected, actual.load()) |
| 923 | |
| 924 | # two-staged vectorized-indexing |
| 925 | indexers2 = [ |
| 926 | { |
| 927 | "dim1": DataArray([[0, 7], [2, 6], [3, 5]], dims=["a", "b"]), |
| 928 | "dim3": DataArray([[0, 4], [1, 3], [2, 2]], dims=["a", "b"]), |
| 929 | }, |
| 930 | {"a": DataArray([0, 1], dims=["c"]), "b": DataArray([0, 1], dims=["c"])}, |
| 931 | ] |
| 932 | multiple_indexing(indexers2) |
| 933 | |
| 934 | # vectorized-slice mixed |
| 935 | indexers3 = [ |
| 936 | { |
| 937 | "dim1": DataArray([[0, 7], [2, 6], [3, 5]], dims=["a", "b"]), |
| 938 | "dim3": slice(None, 10), |
| 939 | } |
| 940 | ] |
| 941 | multiple_indexing(indexers3) |
| 942 | |
| 943 | # vectorized-integer mixed |
| 944 | indexers4 = [ |
| 945 | {"dim3": 0}, |
| 946 | {"dim1": DataArray([[0, 7], [2, 6], [3, 5]], dims=["a", "b"])}, |
| 947 | {"a": slice(None, None, 2)}, |
| 948 | ] |
| 949 | multiple_indexing(indexers4) |
| 950 | |
| 951 | # vectorized-integer mixed |
| 952 | indexers5 = [ |
nothing calls this directly
no test coverage detected