summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2021-09-02 10:28:28 -0600
committerGitHub <noreply@github.com>2021-09-02 10:28:28 -0600
commit95d254027f2fb526fe4c745f330e6fa448a7e4db (patch)
treedceb9f90936601187aa6450139cdf26912b4db3b /numpy/lib
parent47368730049ac394c50d2b73fa51e671c1320984 (diff)
parent7ad8ea7b11e3544b133d8b397dd3bbe4833d3308 (diff)
downloadnumpy-95d254027f2fb526fe4c745f330e6fa448a7e4db.tar.gz
Merge pull request #19815 from mwtoews/maint-ioerror
MAINT: revise OSError aliases (IOError, EnvironmentError)
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/_datasource.py2
-rw-r--r--numpy/lib/format.py5
-rw-r--r--numpy/lib/npyio.py10
-rw-r--r--numpy/lib/tests/test__datasource.py6
4 files changed, 12 insertions, 11 deletions
diff --git a/numpy/lib/_datasource.py b/numpy/lib/_datasource.py
index c790a6462..56b94853d 100644
--- a/numpy/lib/_datasource.py
+++ b/numpy/lib/_datasource.py
@@ -530,7 +530,7 @@ class DataSource:
return _file_openers[ext](found, mode=mode,
encoding=encoding, newline=newline)
else:
- raise IOError("%s not found." % path)
+ raise FileNotFoundError(f"{path} not found.")
class Repository (DataSource):
diff --git a/numpy/lib/format.py b/numpy/lib/format.py
index 6ac66c22a..e566e253d 100644
--- a/numpy/lib/format.py
+++ b/numpy/lib/format.py
@@ -162,7 +162,6 @@ evolved with time and this document is more current.
"""
import numpy
-import io
import warnings
from numpy.lib.utils import safe_eval
from numpy.compat import (
@@ -831,7 +830,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None,
------
ValueError
If the data or the mode is invalid.
- IOError
+ OSError
If the file is not found or cannot be opened correctly.
See Also
@@ -909,7 +908,7 @@ def _read_bytes(fp, size, error_template="ran out of data"):
data += r
if len(r) == 0 or len(data) == size:
break
- except io.BlockingIOError:
+ except BlockingIOError:
pass
if len(data) != size:
msg = "EOF: reading %s, expected %d bytes got %d"
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 6f2a211b6..b91bf440f 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -324,10 +324,12 @@ def load(file, mmap_mode=None, allow_pickle=False, fix_imports=True,
Raises
------
- IOError
+ OSError
If the input file does not exist or cannot be read.
+ UnpicklingError
+ If ``allow_pickle=True``, but the file cannot be loaded as a pickle.
ValueError
- The file contains an object array, but allow_pickle=False given.
+ The file contains an object array, but ``allow_pickle=False`` given.
See Also
--------
@@ -436,8 +438,8 @@ def load(file, mmap_mode=None, allow_pickle=False, fix_imports=True,
try:
return pickle.load(fid, **pickle_kwargs)
except Exception as e:
- raise IOError(
- "Failed to interpret file %s as a pickle" % repr(file)) from e
+ raise pickle.UnpicklingError(
+ f"Failed to interpret file {file!r} as a pickle") from e
def _save_dispatcher(file, arr, allow_pickle=None, fix_imports=None):
diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py
index 1ed7815d9..2738d41c4 100644
--- a/numpy/lib/tests/test__datasource.py
+++ b/numpy/lib/tests/test__datasource.py
@@ -102,10 +102,10 @@ class TestDataSourceOpen:
def test_InvalidHTTP(self):
url = invalid_httpurl()
- assert_raises(IOError, self.ds.open, url)
+ assert_raises(OSError, self.ds.open, url)
try:
self.ds.open(url)
- except IOError as e:
+ except OSError as e:
# Regression test for bug fixed in r4342.
assert_(e.errno is None)
@@ -120,7 +120,7 @@ class TestDataSourceOpen:
def test_InvalidFile(self):
invalid_file = invalid_textfile(self.tmpdir)
- assert_raises(IOError, self.ds.open, invalid_file)
+ assert_raises(OSError, self.ds.open, invalid_file)
def test_ValidGzipFile(self):
try: