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..79f14eef7dff 100644 --- a/python/pyarrow/tests/test_io.py +++ b/python/pyarrow/tests/test_io.py @@ -1216,6 +1216,11 @@ def test_memory_map_resize(tmpdir): assert f.read() == bytes(arr[:SIZE]) +def test_memory_map_resize_uninitialized(): + with pytest.raises(ValueError, match="I/O operation on closed file"): + pa.MemoryMappedFile().resize(0) + + def test_memory_zero_length(tmpdir): path = os.path.join(str(tmpdir), guid()) f = open(path, 'wb')