diff --git a/python/pyarrow/io.pxi b/python/pyarrow/io.pxi index b648fbf66980..bc3ee1841990 100644 --- a/python/pyarrow/io.pxi +++ b/python/pyarrow/io.pxi @@ -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)) def fileno(self): diff --git a/python/pyarrow/tests/test_io.py b/python/pyarrow/tests/test_io.py index 8494a0ee66b4..5e96a3a36772 100644 --- a/python/pyarrow/tests/test_io.py +++ b/python/pyarrow/tests/test_io.py @@ -27,6 +27,7 @@ import pathlib import pytest import random +import subprocess import sys import tempfile import weakref @@ -1216,6 +1217,24 @@ def test_memory_map_resize(tmpdir): assert f.read() == bytes(arr[:SIZE]) +def test_memory_map_resize_uninitialized(): + 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')