From c3b29ca3287ec440cd918f8ae0d1cae4b954e69d Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Wed, 11 Nov 2020 14:01:54 +0200 Subject: DOC: update documentation of numpy.memmap --- numpy/core/memmap.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'numpy/core/memmap.py') diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index cb025736e..23703aa65 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -37,7 +37,10 @@ class memmap(ndarray): This class may at some point be turned into a factory function which returns a view into an mmap buffer. - Delete the memmap instance to close the memmap file. + Flush the memmap instance to write the changes to the file. Currently there + is no API to close the underlying memmap. It is tricky to ensure the + resource is actually closed, since it may be shared between different + memmap instances. Parameters @@ -97,7 +100,7 @@ class memmap(ndarray): flush Flush any changes in memory to file on disk. When you delete a memmap object, flush is called first to write - changes to disk before removing the object. + changes to disk. See also @@ -148,9 +151,9 @@ class memmap(ndarray): >>> fp.filename == path.abspath(filename) True - Deletion flushes memory changes to disk before removing the object: + Flushes memory changes to disk in order to read them back - >>> del fp + >>> fp.flush() Load the memmap and verify data was stored: -- cgit v1.2.1 From f1623beb83e410152ba8764de46a374c6452c089 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Wed, 11 Nov 2020 14:54:29 +0200 Subject: Update numpy/core/memmap.py Co-authored-by: Eric Wieser --- numpy/core/memmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/core/memmap.py') diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index 23703aa65..66653c0c1 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -38,7 +38,7 @@ class memmap(ndarray): which returns a view into an mmap buffer. Flush the memmap instance to write the changes to the file. Currently there - is no API to close the underlying memmap. It is tricky to ensure the + is no API to close the underlying ``mmap``. It is tricky to ensure the resource is actually closed, since it may be shared between different memmap instances. -- cgit v1.2.1 From b2778a8a6d99dfbfee8f09daf6c069d1acf1aa8d Mon Sep 17 00:00:00 2001 From: Bas van Beek Date: Sat, 5 Dec 2020 13:22:39 +0100 Subject: MAINT: Replace `contextlib_nullcontext` with `contextlib.nullcontext` --- numpy/core/memmap.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'numpy/core/memmap.py') diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index 66653c0c1..892ad2540 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -1,8 +1,8 @@ +from contextlib import nullcontext + import numpy as np from .numeric import uint8, ndarray, dtype -from numpy.compat import ( - os_fspath, contextlib_nullcontext, is_pathlib_path -) +from numpy.compat import os_fspath, is_pathlib_path from numpy.core.overrides import set_module __all__ = ['memmap'] @@ -38,7 +38,7 @@ class memmap(ndarray): which returns a view into an mmap buffer. Flush the memmap instance to write the changes to the file. Currently there - is no API to close the underlying ``mmap``. It is tricky to ensure the + is no API to close the underlying ``mmap``. It is tricky to ensure the resource is actually closed, since it may be shared between different memmap instances. @@ -112,7 +112,7 @@ class memmap(ndarray): The memmap object can be used anywhere an ndarray is accepted. Given a memmap ``fp``, ``isinstance(fp, numpy.ndarray)`` returns ``True``. - + Memory-mapped files cannot be larger than 2GB on 32-bit systems. When a memmap causes a file to be created or extended beyond its @@ -223,7 +223,7 @@ class memmap(ndarray): raise ValueError("shape must be given") if hasattr(filename, 'read'): - f_ctx = contextlib_nullcontext(filename) + f_ctx = nullcontext(filename) else: f_ctx = open(os_fspath(filename), ('r' if mode == 'c' else mode)+'b') -- cgit v1.2.1