Test querying a dataset.
(self, backend, engine, parser)
| 7640 | "backend", ["numpy", pytest.param("dask", marks=[requires_dask])] |
| 7641 | ) |
| 7642 | def test_query(self, backend, engine, parser) -> None: |
| 7643 | """Test querying a dataset.""" |
| 7644 | |
| 7645 | # setup test data |
| 7646 | np.random.seed(42) |
| 7647 | a = np.arange(0, 10, 1) |
| 7648 | b = np.random.randint(0, 100, size=10) |
| 7649 | c = np.linspace(0, 1, 20) |
| 7650 | d = np.random.choice(["foo", "bar", "baz"], size=30, replace=True).astype( |
| 7651 | object |
| 7652 | ) |
| 7653 | e = np.arange(0, 10 * 20).reshape(10, 20) |
| 7654 | f = np.random.normal(0, 1, size=(10, 20, 30)) |
| 7655 | if backend == "numpy": |
| 7656 | ds = Dataset( |
| 7657 | { |
| 7658 | "a": ("x", a), |
| 7659 | "b": ("x", b), |
| 7660 | "c": ("y", c), |
| 7661 | "d": ("z", d), |
| 7662 | "e": (("x", "y"), e), |
| 7663 | "f": (("x", "y", "z"), f), |
| 7664 | }, |
| 7665 | coords={ |
| 7666 | "a2": ("x", a), |
| 7667 | "b2": ("x", b), |
| 7668 | "c2": ("y", c), |
| 7669 | "d2": ("z", d), |
| 7670 | "e2": (("x", "y"), e), |
| 7671 | "f2": (("x", "y", "z"), f), |
| 7672 | }, |
| 7673 | ) |
| 7674 | elif backend == "dask": |
| 7675 | ds = Dataset( |
| 7676 | { |
| 7677 | "a": ("x", da.from_array(a, chunks=3)), |
| 7678 | "b": ("x", da.from_array(b, chunks=3)), |
| 7679 | "c": ("y", da.from_array(c, chunks=7)), |
| 7680 | "d": ("z", da.from_array(d, chunks=12)), |
| 7681 | "e": (("x", "y"), da.from_array(e, chunks=(3, 7))), |
| 7682 | "f": (("x", "y", "z"), da.from_array(f, chunks=(3, 7, 12))), |
| 7683 | }, |
| 7684 | coords={ |
| 7685 | "a2": ("x", a), |
| 7686 | "b2": ("x", b), |
| 7687 | "c2": ("y", c), |
| 7688 | "d2": ("z", d), |
| 7689 | "e2": (("x", "y"), e), |
| 7690 | "f2": (("x", "y", "z"), f), |
| 7691 | }, |
| 7692 | ) |
| 7693 | |
| 7694 | # query single dim, single variable |
| 7695 | with raise_if_dask_computes(): |
| 7696 | actual = ds.query(x="a2 > 5", engine=engine, parser=parser) |
| 7697 | expect = ds.isel(x=(a > 5)) |
| 7698 | assert_identical(expect, actual) |
| 7699 |
nothing calls this directly
no test coverage detected