def test_path_objects(tmpdir): # Test compatibility with PEP 519 path-like objects p = pathlib.Path(tmpdir) / 'zzz.bin' obj = 1234 pa.serialize_to(obj, p) res = pa.deserialize_from(p, None) assert res == obj
def test_path_objects(tmpdir): # Test compatibility with PEP 519 path-like objects import pathlib p = pathlib.Path(tmpdir) / 'zzz.bin' obj = 1234 pa.serialize_to(obj, p) res = pa.deserialize_from(p, None) assert res == obj
def serialization_roundtrip(value, f, ctx=serialization_context): f.seek(0) pa.serialize_to(value, f, ctx) f.seek(0) result = pa.deserialize_from(f, None, ctx) assert_equal(value, result) _check_component_roundtrip(value)
def test_numpy_immutable(large_memory_map): with pa.memory_map(large_memory_map, mode="r+") as mmap: obj = np.zeros([10]) mmap.seek(0) pa.serialize_to(obj, mmap, serialization_context) mmap.seek(0) result = pa.deserialize_from(mmap, None, serialization_context) with pytest.raises(ValueError): result[0] = 1.0
def serialization_roundtrip(value, scratch_buffer, ctx=serialization_context): writer = pa.FixedSizeBufferWriter(scratch_buffer) pa.serialize_to(value, writer, ctx) reader = pa.BufferReader(scratch_buffer) result = pa.deserialize_from(reader, None, ctx) assert_equal(value, result) _check_component_roundtrip(value)
def test_serialize_read_concatenated_records(): # ARROW-1996 -- see stream alignment work in ARROW-2840, ARROW-3212 f = pa.BufferOutputStream() pa.serialize_to(12, f) pa.serialize_to(23, f) buf = f.getvalue() f = pa.BufferReader(buf) pa.read_serialized(f).deserialize() pa.read_serialized(f).deserialize()
def test_numpy_immutable(large_buffer): obj = np.zeros([10]) writer = pa.FixedSizeBufferWriter(large_buffer) pa.serialize_to(obj, writer, global_serialization_context) reader = pa.BufferReader(large_buffer) result = pa.deserialize_from(reader, None, global_serialization_context) with pytest.raises(ValueError): result[0] = 1.0
def serialization_roundtrip(value, scratch_buffer, context=global_serialization_context): writer = pa.FixedSizeBufferWriter(scratch_buffer) pa.serialize_to(value, writer, context=context) reader = pa.BufferReader(scratch_buffer) result = pa.deserialize_from(reader, None, context=context) assert_equal(value, result) _check_component_roundtrip(value, context=context)
def serialize_pyarrow(data: bytes, codec: str): """ Serialize an object and compress with a specific codec. Returns the serialized, compressed bytes in a pyarrow.Buffer. The caller is responsible for reading the returned bytes into a file, if necessary. Should be used in conjunction with `deserialize_pyarrow`. """ raw = pa.BufferOutputStream() with pa.CompressedOutputStream(raw, compression=codec) as compressed: pa.serialize_to(data, compressed, context=serialization_context) return raw.getvalue()
def test_serialization_deprecated(): with pytest.warns(FutureWarning): ser = pa.serialize(1) with pytest.warns(FutureWarning): pa.deserialize(ser.to_buffer()) f = pa.BufferOutputStream() with pytest.warns(FutureWarning): pa.serialize_to(12, f) buf = f.getvalue() f = pa.BufferReader(buf) with pytest.warns(FutureWarning): pa.read_serialized(f).deserialize() with pytest.warns(FutureWarning): pa.default_serialization_context() context = pa.lib.SerializationContext() with pytest.warns(FutureWarning): pa.register_default_serialization_handlers(context)
def serialization_roundtrip(value, f): f.seek(0) pa.serialize_to(value, f, serialization_context) f.seek(0) result = pa.deserialize_from(f, None, serialization_context) assert_equal(value, result)