Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/pyarrow/io.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,8 @@ cdef class FixedSizeBufferWriter(NativeFile):
"""

def __cinit__(self, Buffer buffer):
if not buffer.is_mutable:
raise ValueError("pa.FixedSizeBufferWriter() requires a mutable buffer")
self.output_stream.reset(new CFixedSizeBufferWriter(buffer.buffer))
self.is_writable = True

Expand Down
13 changes: 13 additions & 0 deletions python/pyarrow/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,19 @@ def test_output_stream_errors(tmpdir):
with pytest.raises(ValueError):
pa.output_stream(buf, compression="foo")

for arg in [memoryview(b"x"), pa.py_buffer(b"x"),
memoryview(b""), pa.py_buffer(b"")]:
with pytest.raises(ValueError, match="requires a mutable buffer"):
pa.output_stream(arg)

for arg in [pa.py_buffer(b"x"), pa.py_buffer(b"")]:
with pytest.raises(ValueError, match="requires a mutable buffer"):
pa.FixedSizeBufferWriter(arg)

for arg in [memoryview(bytearray(1)), pa.py_buffer(bytearray(1))]:
with pa.output_stream(arg) as stream:
stream.write(b"x")

for arg in [bytearray(), StringIO()]:
with pytest.raises(TypeError):
pa.output_stream(arg)
Expand Down