Example #1
0
def test_softlinks_recursion():
    with tmp_filename() as fn:
        A = np.random.randn(3, 3)
        df = pd.DataFrame({
            "int": np.arange(3),
            "name": ["zero", "one", "two"]
        })
        AA = 4
        s = dict(A=A,
                 B=A,
                 c=A,
                 d=A,
                 f=A,
                 g=[A, A, A],
                 AA=AA,
                 h=AA,
                 df=df,
                 df2=df)
        s["g"].append(s)
        n = reconstruct(fn, s)
        assert n["g"][0] is n["A"]
        assert (n["A"] is n["B"] is n["c"] is n["d"] is n["f"] is n["g"][0] is
                n["g"][1] is n["g"][2])
        assert n["g"][3] is n
        assert n["AA"] == AA == n["h"]
        assert n["df"] is n["df2"]
        assert (n["df"] == df).all().all()

        # test 'sel' option on link ... need to read two vars
        # to ensure at least one is a link:
        col1 = h5io.load(fn, "/A", (slice(None), slice(1, 2)))
        assert np.all(A[:, 1] == col1.flatten())
        col1 = h5io.load(fn, "/B", (slice(None), slice(1, 2)))
        assert np.all(A[:, 1] == col1.flatten())
Example #2
0
def test_load_multiple_groups():
    with tmp_filename() as fn:
        x = dict(one=np.ones(10), two="string", three=200)
        h5io.save(fn, x)

        one, three = h5io.load(fn, ["/one", "/three"])
        np.testing.assert_array_equal(one, x["one"])
        assert three == x["three"]

        three, two = h5io.load(fn, ["/three", "/two"])
        assert three == x["three"]
        assert two == x["two"]
Example #3
0
def test_load_group():
    with tmp_filename() as fn:
        x = dict(one=np.ones(10), two="string")
        h5io.save(fn, x)

        one = h5io.load(fn, "/one")
        np.testing.assert_array_equal(one, x["one"])
        two = h5io.load(fn, "/two")
        assert two == x["two"]

        full = h5io.load(fn, "/")
        np.testing.assert_array_equal(x["one"], full["one"])
        assert x["two"] == full["two"]
Example #4
0
def test_force_pickle1():
    with tmp_filename() as fn:
        x = dict(one=dict(two=np.arange(10)), three="string")
        xf = dict(one=dict(two=x["one"]["two"]), three=x["three"])

        h5io.save(fn, xf)
        xs = h5io.load(fn)

        np.testing.assert_array_equal(x["one"]["two"], xs["one"]["two"])
        assert x["three"] == xs["three"]

        # Try direct loading one
        two = h5io.load(fn, "/one/two")
        np.testing.assert_array_equal(x["one"]["two"], two)
Example #5
0
def test_compression_true():
    rs = np.random.RandomState(1234)
    with tmp_filename() as fn:
        x = rs.normal(size=(1000, 5))
        for comp in [None, True, "blosc", "zlib", ("zlib", 5)]:
            h5io.save(fn, x, compression=comp)
            x1 = h5io.load(fn)
            assert (x == x1).all()
Example #6
0
def test_load_slice():
    with tmp_filename() as fn:
        x = np.arange(3 * 4 * 5).reshape((3, 4, 5))
        h5io.save(fn, dict(x=x))

        s = slice(None, 2)
        xs = h5io.load(fn, "/x", sel=s)
        np.testing.assert_array_equal(xs, x[s])

        s = (slice(None), slice(1, 3))
        xs = h5io.load(fn, "/x", sel=s)
        np.testing.assert_array_equal(xs, x[s])

        xs = h5io.load(fn, sel=s, unpack=True)
        np.testing.assert_array_equal(xs, x[s])

        h5io.save(fn, x)
        xs = h5io.load(fn, sel=s)
        np.testing.assert_array_equal(xs, x[s])
Example #7
0
def assert_array(fn, x):
    h5io.save(fn, x)
    x1 = h5io.load(fn)
    np.testing.assert_array_equal(x, x1)
Example #8
0
def reconstruct(fn, x):
    h5io.save(fn, x)
    return h5io.load(fn)