MCPcopy Create free account
hub / github.com/dask/dask / test_to_hdf5

Function test_to_hdf5

dask/array/tests/test_array_core.py:2458–2494  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2456
2457
2458def test_to_hdf5():
2459 h5py = pytest.importorskip("h5py")
2460 x = da.ones((4, 4), chunks=(2, 2))
2461 y = da.ones(4, chunks=2, dtype="i4")
2462
2463 with tmpfile(".hdf5") as fn:
2464 x.to_hdf5(fn, "/x")
2465 with h5py.File(fn, mode="r+") as f:
2466 d = f["/x"]
2467
2468 assert_eq(d[:], x)
2469 assert d.chunks == (2, 2)
2470
2471 with tmpfile(".hdf5") as fn:
2472 x.to_hdf5(fn, "/x", chunks=None)
2473 with h5py.File(fn, mode="r+") as f:
2474 d = f["/x"]
2475
2476 assert_eq(d[:], x)
2477 assert d.chunks is None
2478
2479 with tmpfile(".hdf5") as fn:
2480 x.to_hdf5(fn, "/x", chunks=(1, 1))
2481 with h5py.File(fn, mode="r+") as f:
2482 d = f["/x"]
2483
2484 assert_eq(d[:], x)
2485 assert d.chunks == (1, 1)
2486
2487 with tmpfile(".hdf5") as fn:
2488 da.to_hdf5(fn, {"/x": x, "/y": y})
2489
2490 with h5py.File(fn, mode="r+") as f:
2491 assert_eq(f["/x"][:], x)
2492 assert f["/x"].chunks == (2, 2)
2493 assert_eq(f["/y"][:], y)
2494 assert f["/y"].chunks == (2,)
2495
2496
2497def test_to_dask_dataframe():

Callers

nothing calls this directly

Calls 4

tmpfileFunction · 0.90
assert_eqFunction · 0.90
to_hdf5Method · 0.80
onesMethod · 0.45

Tested by

no test coverage detected