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
1 change: 1 addition & 0 deletions python/pyarrow/io.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ cdef class MemoryMappedFile(NativeFile):
----------
new_size : new size in bytes
"""
self._assert_open()
check_status(self.handle.get().Resize(new_size))
Comment thread
1fanwang marked this conversation as resolved.

def fileno(self):
Expand Down
19 changes: 19 additions & 0 deletions python/pyarrow/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import pathlib
import pytest
import random
import subprocess
import sys
import tempfile
import weakref
Expand Down Expand Up @@ -1216,6 +1217,24 @@ def test_memory_map_resize(tmpdir):
assert f.read() == bytes(arr[:SIZE])


def test_memory_map_resize_uninitialized():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use simple with pytest.raises(ValueError, match="***"): syntax?

code = """if 1:
import pyarrow as pa

try:
pa.MemoryMappedFile().resize(0)
except ValueError as exc:
assert str(exc) == "I/O operation on closed file"
else:
raise AssertionError("expected ValueError")
"""
res = subprocess.run([sys.executable, "-c", code],
universal_newlines=True, stderr=subprocess.PIPE)
if res.returncode != 0:
print(res.stderr, file=sys.stderr)
res.check_returncode()


def test_memory_zero_length(tmpdir):
path = os.path.join(str(tmpdir), guid())
f = open(path, 'wb')
Expand Down