From bd3309d11bc03feee08b6e49b1c7df03c2058657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Fri, 15 Jun 2018 23:54:47 +0200 Subject: [PATCH 1/8] ENH: Improve support for pathlib.Path objects in load functions Add support for pathlib.Path when "mmap_mode" is specified in np.load "Closes #11342". Add support for pathlib.Path in np.core.records.fromfile. --- doc/release/1.15.0-notes.rst | 6 ++++++ numpy/core/records.py | 11 +++++++---- numpy/core/tests/test_records.py | 21 ++++++++++++++++++++- numpy/lib/format.py | 22 +++++++++++++++------- numpy/lib/tests/test_io.py | 24 +++++++++++++++++++++++- 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/doc/release/1.15.0-notes.rst b/doc/release/1.15.0-notes.rst index cc193530c706..da90509d57de 100644 --- a/doc/release/1.15.0-notes.rst +++ b/doc/release/1.15.0-notes.rst @@ -216,6 +216,12 @@ Like ``np.percentile`` and ``np.nanpercentile``, but takes quantiles in [0, 1] rather than percentiles in [0, 100]. ``np.percentile`` is now a thin wrapper around ``np.quantile`` with the extra step of dividing by 100. +``pathlib.Path`` support for more functions +------------------------------------------- +The ``np.core.records.fromfile`` function now supports ``pathlib.Path`` +objects in addition to a string or a file object. Furthermore, the +``np.load`` function now also supports ``pathlib.Path`` objects when +using memory mapping (``mmap_mode`` keyword argument). Build system ------------ diff --git a/numpy/core/records.py b/numpy/core/records.py index 612d39322c3e..a3dde9a8808f 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -42,7 +42,7 @@ from . import numeric as sb from . import numerictypes as nt -from numpy.compat import isfileobj, bytes, long +from numpy.compat import isfileobj, bytes, long, is_pathlib_path from .arrayprint import get_printoptions # All of the functions allow formats to be a dtype @@ -737,9 +737,9 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None, names=None, titles=None, aligned=False, byteorder=None): """Create an array from binary file data - If file is a string then that file is opened, else it is assumed - to be a file object. The file object must support random access - (i.e. it must have tell and seek methods). + If file is a string or a pathlib.Path then that file is opened, + else it is assumed to be a file object. The file object must + support random access (i.e. it must have tell and seek methods). >>> from tempfile import TemporaryFile >>> a = np.empty(10,dtype='f8,i4,a5') @@ -767,6 +767,9 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None, if isinstance(fd, str): name = 1 fd = open(fd, 'rb') + elif is_pathlib_path(fd): + name = 1 + fd = fd.open('rb') if (offset > 0): fd.seek(offset, 1) size = get_remaining_size(fd) diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py index d7c7d16e3f74..d00cac6201b9 100644 --- a/numpy/core/tests/test_records.py +++ b/numpy/core/tests/test_records.py @@ -14,9 +14,10 @@ import pytest import numpy as np +from numpy.compat import Path from numpy.testing import ( assert_, assert_equal, assert_array_equal, assert_array_almost_equal, - assert_raises, assert_warns + assert_raises, assert_warns, temppath ) @@ -325,6 +326,24 @@ def test_zero_width_strings(self): assert_equal(rec['f1'], [b'', b'', b'']) +@pytest.mark.skipif(Path is None, reason="No pathlib.Path") +class TestPathUsage(object): + # Test that pathlib.Path can be used + def test_tofile_fromfile(self): + with temppath(suffix='.bin') as path: + path = Path(path) + a = np.empty(10, dtype='f8,i4,a5') + a[5] = (0.5,10,'abcde') + a.newbyteorder('<') + with path.open("wb") as fd: + a.tofile(fd) + x = np.core.records.fromfile(path, + formats='f8,i4,a5', + shape=10, + byteorder='<') + assert_array_equal(x, a) + + class TestRecord(object): def setup(self): self.data = np.rec.fromrecords([(1, 2, 3), (4, 5, 6)], diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 23eac7e7dafe..99e476121e36 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -161,7 +161,9 @@ import io import warnings from numpy.lib.utils import safe_eval -from numpy.compat import asbytes, asstr, isfileobj, long, basestring +from numpy.compat import ( + asbytes, asstr, isfileobj, long, basestring, is_pathlib_path + ) if sys.version_info[0] >= 3: import pickle @@ -709,7 +711,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, Parameters ---------- - filename : str + filename : str or pathlib.Path instance The name of the file on disk. This may *not* be a file-like object. mode : str, optional @@ -750,9 +752,9 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, memmap """ - if not isinstance(filename, basestring): - raise ValueError("Filename must be a string. Memmap cannot use" - " existing file handles.") + if not (isinstance(filename, basestring) or is_pathlib_path(filename)): + raise ValueError("Filename must be a string or a pathlib.Path." + " Memmap cannot use existing file handles.") if 'w' in mode: # We are creating the file, not reading it. @@ -770,7 +772,10 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, shape=shape, ) # If we got here, then it should be safe to create the file. - fp = open(filename, mode+'b') + if is_pathlib_path(filename): + fp = filename.open(mode+'b') + else: + fp = open(filename, mode+'b') try: used_ver = _write_array_header(fp, d, version) # this warning can be removed when 1.9 has aged enough @@ -782,7 +787,10 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, fp.close() else: # Read the header of the file first. - fp = open(filename, 'rb') + if is_pathlib_path(filename): + fp = filename.open('rb') + else: + fp = open(filename, 'rb') try: version = read_magic(fp) _check_version(version) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index f58c9e33dbc2..df0ed9766ae8 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -2252,11 +2252,33 @@ def test_loadtxt(self): assert_array_equal(x, a) def test_save_load(self): - # Test that pathlib.Path instances can be used with savez. + # Test that pathlib.Path instances can be used with save. + with temppath(suffix='.npy') as path: + path = Path(path) + a = np.array([[1, 2], [3, 4]], int) + np.save(path, a) + data = np.load(path) + assert_array_equal(data, a) + + def test_save_load_memmap(self): + # Test that pathlib.Path instances can be loaded mem-mapped. + with temppath(suffix='.npy') as path: + path = Path(path) + a = np.array([[1, 2], [3, 4]], int) + np.save(path, a) + data = np.load(path, mmap_mode='r') + assert_array_equal(data, a) + + def test_save_load_memmap_readwrite(self): + # Test that pathlib.Path instances can be written mem-mapped. with temppath(suffix='.npy') as path: path = Path(path) a = np.array([[1, 2], [3, 4]], int) np.save(path, a) + b = np.load(path, mmap_mode='r+') + a[0][0] = 5 + b[0][0] = 5 + del b # closes the file data = np.load(path) assert_array_equal(data, a) From c4e5aa10ab630a26019af621ee77d532c99cb076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Sat, 16 Jun 2018 13:47:40 +0200 Subject: [PATCH 2/8] tests: fix permission error on windows (memmap file not closed) --- numpy/lib/tests/test_io.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index df0ed9766ae8..a53fd57b330f 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -2268,6 +2268,7 @@ def test_save_load_memmap(self): np.save(path, a) data = np.load(path, mmap_mode='r') assert_array_equal(data, a) + del data def test_save_load_memmap_readwrite(self): # Test that pathlib.Path instances can be written mem-mapped. From 07cc4b66c5e062305d3fc7ef83ed9a5607ad72f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Fri, 15 Jun 2018 23:54:47 +0200 Subject: [PATCH 3/8] ENH: Improve support for pathlib.Path objects in load functions Add support for pathlib.Path when "mmap_mode" is specified in np.load "Closes #11342". Add support for pathlib.Path in np.core.records.fromfile. --- doc/release/1.15.0-notes.rst | 6 ++++++ numpy/core/records.py | 11 +++++++---- numpy/core/tests/test_records.py | 21 ++++++++++++++++++++- numpy/lib/format.py | 22 +++++++++++++++------- numpy/lib/tests/test_io.py | 24 +++++++++++++++++++++++- 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/doc/release/1.15.0-notes.rst b/doc/release/1.15.0-notes.rst index 7235ca915967..5c694e595566 100644 --- a/doc/release/1.15.0-notes.rst +++ b/doc/release/1.15.0-notes.rst @@ -261,6 +261,12 @@ Like ``np.percentile`` and ``np.nanpercentile``, but takes quantiles in [0, 1] rather than percentiles in [0, 100]. ``np.percentile`` is now a thin wrapper around ``np.quantile`` with the extra step of dividing by 100. +``pathlib.Path`` support for more functions +------------------------------------------- +The ``np.core.records.fromfile`` function now supports ``pathlib.Path`` +objects in addition to a string or a file object. Furthermore, the +``np.load`` function now also supports ``pathlib.Path`` objects when +using memory mapping (``mmap_mode`` keyword argument). Build system ------------ diff --git a/numpy/core/records.py b/numpy/core/records.py index a483871babf1..2d4760a68af3 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -42,7 +42,7 @@ from . import numeric as sb from . import numerictypes as nt -from numpy.compat import isfileobj, bytes, long, unicode +from numpy.compat import isfileobj, bytes, long, unicode, is_pathlib_path from .arrayprint import get_printoptions # All of the functions allow formats to be a dtype @@ -737,9 +737,9 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None, names=None, titles=None, aligned=False, byteorder=None): """Create an array from binary file data - If file is a string then that file is opened, else it is assumed - to be a file object. The file object must support random access - (i.e. it must have tell and seek methods). + If file is a string or a pathlib.Path then that file is opened, + else it is assumed to be a file object. The file object must + support random access (i.e. it must have tell and seek methods). >>> from tempfile import TemporaryFile >>> a = np.empty(10,dtype='f8,i4,a5') @@ -767,6 +767,9 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None, if isinstance(fd, str): name = 1 fd = open(fd, 'rb') + elif is_pathlib_path(fd): + name = 1 + fd = fd.open('rb') if (offset > 0): fd.seek(offset, 1) size = get_remaining_size(fd) diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py index a77eef40405d..af6c86b9ec77 100644 --- a/numpy/core/tests/test_records.py +++ b/numpy/core/tests/test_records.py @@ -13,9 +13,10 @@ import pytest import numpy as np +from numpy.compat import Path from numpy.testing import ( assert_, assert_equal, assert_array_equal, assert_array_almost_equal, - assert_raises, assert_warns + assert_raises, assert_warns, temppath ) from numpy.core.numeric import pickle @@ -325,6 +326,24 @@ def test_zero_width_strings(self): assert_equal(rec['f1'], [b'', b'', b'']) +@pytest.mark.skipif(Path is None, reason="No pathlib.Path") +class TestPathUsage(object): + # Test that pathlib.Path can be used + def test_tofile_fromfile(self): + with temppath(suffix='.bin') as path: + path = Path(path) + a = np.empty(10, dtype='f8,i4,a5') + a[5] = (0.5,10,'abcde') + a.newbyteorder('<') + with path.open("wb") as fd: + a.tofile(fd) + x = np.core.records.fromfile(path, + formats='f8,i4,a5', + shape=10, + byteorder='<') + assert_array_equal(x, a) + + class TestRecord(object): def setup(self): self.data = np.rec.fromrecords([(1, 2, 3), (4, 5, 6)], diff --git a/numpy/lib/format.py b/numpy/lib/format.py index e25868236d20..3a64307d3540 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -161,7 +161,9 @@ import io import warnings from numpy.lib.utils import safe_eval -from numpy.compat import asbytes, asstr, isfileobj, long, basestring +from numpy.compat import ( + asbytes, asstr, isfileobj, long, basestring, is_pathlib_path + ) from numpy.core.numeric import pickle @@ -706,7 +708,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, Parameters ---------- - filename : str + filename : str or pathlib.Path instance The name of the file on disk. This may *not* be a file-like object. mode : str, optional @@ -747,9 +749,9 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, memmap """ - if not isinstance(filename, basestring): - raise ValueError("Filename must be a string. Memmap cannot use" - " existing file handles.") + if not (isinstance(filename, basestring) or is_pathlib_path(filename)): + raise ValueError("Filename must be a string or a pathlib.Path." + " Memmap cannot use existing file handles.") if 'w' in mode: # We are creating the file, not reading it. @@ -767,7 +769,10 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, shape=shape, ) # If we got here, then it should be safe to create the file. - fp = open(filename, mode+'b') + if is_pathlib_path(filename): + fp = filename.open(mode+'b') + else: + fp = open(filename, mode+'b') try: used_ver = _write_array_header(fp, d, version) # this warning can be removed when 1.9 has aged enough @@ -779,7 +784,10 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, fp.close() else: # Read the header of the file first. - fp = open(filename, 'rb') + if is_pathlib_path(filename): + fp = filename.open('rb') + else: + fp = open(filename, 'rb') try: version = read_magic(fp) _check_version(version) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 08800ff97f5b..5699730cb369 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -2295,11 +2295,33 @@ def test_loadtxt(self): assert_array_equal(x, a) def test_save_load(self): - # Test that pathlib.Path instances can be used with savez. + # Test that pathlib.Path instances can be used with save. + with temppath(suffix='.npy') as path: + path = Path(path) + a = np.array([[1, 2], [3, 4]], int) + np.save(path, a) + data = np.load(path) + assert_array_equal(data, a) + + def test_save_load_memmap(self): + # Test that pathlib.Path instances can be loaded mem-mapped. + with temppath(suffix='.npy') as path: + path = Path(path) + a = np.array([[1, 2], [3, 4]], int) + np.save(path, a) + data = np.load(path, mmap_mode='r') + assert_array_equal(data, a) + + def test_save_load_memmap_readwrite(self): + # Test that pathlib.Path instances can be written mem-mapped. with temppath(suffix='.npy') as path: path = Path(path) a = np.array([[1, 2], [3, 4]], int) np.save(path, a) + b = np.load(path, mmap_mode='r+') + a[0][0] = 5 + b[0][0] = 5 + del b # closes the file data = np.load(path) assert_array_equal(data, a) From d2d15719973315c8271b47935a2a2e1c29bed465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Sat, 16 Jun 2018 13:47:40 +0200 Subject: [PATCH 4/8] tests: fix permission error on windows (memmap file not closed) --- numpy/lib/tests/test_io.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 5699730cb369..872757bdaf7e 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -2311,6 +2311,7 @@ def test_save_load_memmap(self): np.save(path, a) data = np.load(path, mmap_mode='r') assert_array_equal(data, a) + del data def test_save_load_memmap_readwrite(self): # Test that pathlib.Path instances can be written mem-mapped. From 84a0b77bbb01720a08a22029ae23303c5b9859fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Thu, 1 Nov 2018 09:06:12 +0100 Subject: [PATCH 5/8] tests: add comment --- numpy/lib/tests/test_io.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 872757bdaf7e..b746937b9655 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -2311,6 +2311,7 @@ def test_save_load_memmap(self): np.save(path, a) data = np.load(path, mmap_mode='r') assert_array_equal(data, a) + # close the mem-mapped file del data def test_save_load_memmap_readwrite(self): From 271f3e3bc0c7b1fbfad595ee9209c5c973f7469e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Thu, 1 Nov 2018 10:02:32 +0100 Subject: [PATCH 6/8] use new os_fspath --- numpy/core/records.py | 15 ++++++++------- numpy/lib/format.py | 14 ++++---------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/numpy/core/records.py b/numpy/core/records.py index 2d4760a68af3..cb527cdb3aed 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -42,7 +42,7 @@ from . import numeric as sb from . import numerictypes as nt -from numpy.compat import isfileobj, bytes, long, unicode, is_pathlib_path +from numpy.compat import isfileobj, bytes, long, unicode, os_fspath from .arrayprint import get_printoptions # All of the functions allow formats to be a dtype @@ -763,13 +763,14 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None, elif isinstance(shape, (int, long)): shape = (shape,) - name = 0 - if isinstance(fd, str): - name = 1 - fd = open(fd, 'rb') - elif is_pathlib_path(fd): + if isfileobj(fd): + # file already opened + name = 0 + else: + # open file + fd = open(os_fspath(fd), 'rb') name = 1 - fd = fd.open('rb') + if (offset > 0): fd.seek(offset, 1) size = get_remaining_size(fd) diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 3a64307d3540..e7806f7aff8c 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -162,7 +162,7 @@ import warnings from numpy.lib.utils import safe_eval from numpy.compat import ( - asbytes, asstr, isfileobj, long, basestring, is_pathlib_path + asbytes, asstr, isfileobj, long, os_fspath ) from numpy.core.numeric import pickle @@ -749,7 +749,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, memmap """ - if not (isinstance(filename, basestring) or is_pathlib_path(filename)): + if isfileobj(filename): raise ValueError("Filename must be a string or a pathlib.Path." " Memmap cannot use existing file handles.") @@ -769,10 +769,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, shape=shape, ) # If we got here, then it should be safe to create the file. - if is_pathlib_path(filename): - fp = filename.open(mode+'b') - else: - fp = open(filename, mode+'b') + fp = open(os_fspath(filename), mode+'b') try: used_ver = _write_array_header(fp, d, version) # this warning can be removed when 1.9 has aged enough @@ -784,10 +781,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, fp.close() else: # Read the header of the file first. - if is_pathlib_path(filename): - fp = filename.open('rb') - else: - fp = open(filename, 'rb') + fp = open(os_fspath(filename), 'rb') try: version = read_magic(fp) _check_version(version) From 5ce8d9584a0e38bdf93ccf69fb90d1451237ede3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Thu, 1 Nov 2018 12:07:11 +0100 Subject: [PATCH 7/8] docs: update path-like references --- doc/release/1.15.0-notes.rst | 9 +++++---- numpy/core/records.py | 2 +- numpy/lib/format.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/release/1.15.0-notes.rst b/doc/release/1.15.0-notes.rst index 5c694e595566..4df08b6b6bd1 100644 --- a/doc/release/1.15.0-notes.rst +++ b/doc/release/1.15.0-notes.rst @@ -261,13 +261,14 @@ Like ``np.percentile`` and ``np.nanpercentile``, but takes quantiles in [0, 1] rather than percentiles in [0, 100]. ``np.percentile`` is now a thin wrapper around ``np.quantile`` with the extra step of dividing by 100. -``pathlib.Path`` support for more functions -------------------------------------------- +Support path-like objects for more functions +-------------------------------------------- The ``np.core.records.fromfile`` function now supports ``pathlib.Path`` -objects in addition to a string or a file object. Furthermore, the -``np.load`` function now also supports ``pathlib.Path`` objects when +and other path-like objects in addition to a file object. Furthermore, the +``np.load`` function now also supports path-like objects when using memory mapping (``mmap_mode`` keyword argument). + Build system ------------ Added experimental support for the 64-bit RISC-V architecture. diff --git a/numpy/core/records.py b/numpy/core/records.py index cb527cdb3aed..1b596e4de578 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -737,7 +737,7 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None, names=None, titles=None, aligned=False, byteorder=None): """Create an array from binary file data - If file is a string or a pathlib.Path then that file is opened, + If file is a string or a path-like object then that file is opened, else it is assumed to be a file object. The file object must support random access (i.e. it must have tell and seek methods). diff --git a/numpy/lib/format.py b/numpy/lib/format.py index e7806f7aff8c..1ef3dca47ec5 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -708,7 +708,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, Parameters ---------- - filename : str or pathlib.Path instance + filename : str or path-like The name of the file on disk. This may *not* be a file-like object. mode : str, optional @@ -750,7 +750,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, """ if isfileobj(filename): - raise ValueError("Filename must be a string or a pathlib.Path." + raise ValueError("Filename must be a string or a path-like object." " Memmap cannot use existing file handles.") if 'w' in mode: From 05ddb688f9d4f501fbd15154338021568e27c0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Thu, 1 Nov 2018 15:29:20 +0100 Subject: [PATCH 8/8] update release notes --- doc/release/1.15.0-notes.rst | 7 ------- doc/release/1.16.0-notes.rst | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/release/1.15.0-notes.rst b/doc/release/1.15.0-notes.rst index 4df08b6b6bd1..7235ca915967 100644 --- a/doc/release/1.15.0-notes.rst +++ b/doc/release/1.15.0-notes.rst @@ -261,13 +261,6 @@ Like ``np.percentile`` and ``np.nanpercentile``, but takes quantiles in [0, 1] rather than percentiles in [0, 100]. ``np.percentile`` is now a thin wrapper around ``np.quantile`` with the extra step of dividing by 100. -Support path-like objects for more functions --------------------------------------------- -The ``np.core.records.fromfile`` function now supports ``pathlib.Path`` -and other path-like objects in addition to a file object. Furthermore, the -``np.load`` function now also supports path-like objects when -using memory mapping (``mmap_mode`` keyword argument). - Build system ------------ diff --git a/doc/release/1.16.0-notes.rst b/doc/release/1.16.0-notes.rst index 89a4623e19f5..bb2b1778233f 100644 --- a/doc/release/1.16.0-notes.rst +++ b/doc/release/1.16.0-notes.rst @@ -273,6 +273,13 @@ Speedup ``np.take`` for read-only arrays The implementation of ``np.take`` no longer makes an unnecessary copy of the source array when its ``writeable`` flag is set to ``False``. +Support path-like objects for more functions +-------------------------------------------- +The ``np.core.records.fromfile`` function now supports ``pathlib.Path`` +and other path-like objects in addition to a file object. Furthermore, the +``np.load`` function now also supports path-like objects when +using memory mapping (``mmap_mode`` keyword argument). + Changes =======