()
| 4509 | |
| 4510 | |
| 4511 | def test_map_partition_sparse(): |
| 4512 | sparse = pytest.importorskip("sparse") |
| 4513 | # Avoid searchsorted failure. |
| 4514 | pytest.importorskip("numba", minversion="0.40.0") |
| 4515 | |
| 4516 | df = pd.DataFrame( |
| 4517 | {"x": [1, 2, 3, 4, 5], "y": [6.0, 7.0, 8.0, 9.0, 10.0]}, |
| 4518 | index=["a", "b", "c", "d", "e"], |
| 4519 | ) |
| 4520 | ddf = dd.from_pandas(df, npartitions=2) |
| 4521 | |
| 4522 | def f(d): |
| 4523 | return sparse.COO(np.array(d)) |
| 4524 | |
| 4525 | for pre in [lambda a: a, lambda a: a.x]: |
| 4526 | expected = f(pre(df)) |
| 4527 | result = pre(ddf).map_partitions(f) |
| 4528 | assert isinstance(result, da.Array) |
| 4529 | computed = result.compute() |
| 4530 | assert (computed.data == expected.data).all() |
| 4531 | assert (computed.coords == expected.coords).all() |
| 4532 | |
| 4533 | |
| 4534 | def test_mixed_dask_array_operations(): |
nothing calls this directly
no test coverage detected