def test_serializability(): state = da.random.RandomState(5) x = state.normal(10, 1, size=10, chunks=5) y = _loads(_dumps(x)) assert (x.compute() == y.compute()).all()
def test_serializability(): state = da.random.RandomState(5) x = state.normal(10, 1, size=10, chunks=5) y = _loads(_dumps(x)) assert_eq(x, y)
def test_pickle_globals(): """ For the function f(x) defined below, the only globals added in pickling should be 'np' and '__builtins__'""" def f(x): return np.sin(x) + np.cos(x) assert set(["np", "__builtins__"]) == set(_loads(_dumps(f)).__globals__.keys())
def test_pickle_globals(): """ For the function f(x) defined below, the only globals added in pickling should be 'np' and '__builtins__'""" def f(x): return np.sin(x) + np.cos(x) assert set(['np', '__builtins__']) == set(_loads(_dumps(f)).__globals__.keys())
def test_pickle_kwargs(): """Test that out-of-band pickling works Note cloudpickle does not support this argument: https://github.com/cloudpipe/cloudpickle/issues/213 """ b = _dumps(my_small_function_global, fix_imports=True) assert b"my_small_function_global" in b assert b"unrelated_function_global" not in b assert b"numpy" not in b my_small_function_global_2 = _loads(b, fix_imports=True) assert my_small_function_global_2(2, 3) == 5
def test_out_of_band_pickling(): """Test that out-of-band pickling works""" np = pytest.importorskip("numpy") a = np.arange(5) l = [] b = _dumps(a, buffer_callback=l.append) assert len(l) == 1 assert isinstance(l[0], pickle.PickleBuffer) assert memoryview(l[0]) == memoryview(a) a2 = _loads(b, buffers=l) assert np.all(a == a2)
def test_out_of_band_pickling(): """Test that out-of-band pickling works""" if has_cloudpickle: if cloudpickle.__version__ < LooseVersion("1.3.0"): pytest.skip("when using cloudpickle, it must be version 1.3.0+") a = np.arange(5) l = [] b = _dumps(a, buffer_callback=l.append) assert len(l) == 1 assert isinstance(l[0], pickle.PickleBuffer) assert memoryview(l[0]) == memoryview(a) a2 = _loads(b, buffers=l) assert np.all(a == a2)