8000 MAINT: Remove old PY_VERSION_HEX and sys.version_info code by hugovk · Pull Request #17235 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Remove old PY_VERSION_HEX and sys.version_info code #17235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
MAINT: Remove old sys.version_info code
  • Loading branch information
hugovk committed Sep 3, 2020
commit d09e192f05fae7d2e13735c82714b0bc140a0d9f
31 changes: 5 additions & 26 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ from typing import (
Sequence,
Sized,
SupportsAbs,
SupportsBytes,
SupportsComplex,
SupportsFloat,
SupportsInt,
Expand All @@ -33,12 +34,6 @@ from typing import (
Union,
)

if sys.version_info[0] < 3:
class SupportsBytes: ...

else:
from typing import SupportsBytes

if sys.version_info >= (3, 8):
from typing import Literal, Protocol
else:
Expand Down Expand Up @@ -192,14 +187,8 @@ class _ArrayOrScalarCommon(
def __int__(self) -> int: ...
def __float__(self) -> float: ...
def __complex__(self) -> complex: ...
if sys.version_info[0] < 3:
def __oct__(self) -> str: ...
def __hex__(self) -> str: ...
def __nonzero__(self) -> bool: ...
def __unicode__(self) -> Text: ...
else:
def __bool__(self) -> bool: ...
def __bytes__(self) -> bytes: ...
def __bool__(self) -> bool: ...
def __bytes__(self) -> bytes: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def __copy__(self: _ArraySelf) -> _ArraySelf: ...
Expand All @@ -219,10 +208,6 @@ class _ArrayOrScalarCommon(
def __mul__(self, other): ...
def __rmul__(self, other): ...
def __imul__(self, other): ...
if sys.version_info[0] < 3:
def __div__(self, other): ...
def __rdiv__(self, other): ...
def __idiv__(self, other): ...
def __truediv__(self, other): ...
def __rtruediv__(self, other): ...
def __itruediv__(self, other): ...
Expand Down Expand Up @@ -253,9 +238,8 @@ class _ArrayOrScalarCommon(
def __or__(self, other): ...
def __ror__(self, other): ...
def __ior__(self, other): ...
if sys.version_info[:2] >= (3, 5):
def __matmul__(self, other): ...
def __rmatmul__(self, other): ...
def __matmul__(self, other): ...
def __rmatmul__(self, other): ...
def __neg__(self: _ArraySelf) -> _ArraySelf: ...
def __pos__(self: _ArraySelf) -> _ArraySelf: ...
def __abs__(self: _ArraySelf) -> _ArraySelf: ...
Expand Down Expand Up @@ -434,11 +418,6 @@ class timedelta64(signedinteger):
@overload
def __add__(self, other: datetime64) -> datetime64: ...
def __sub__(self, other: Union[timedelta64, int]) -> timedelta64: ...
if sys.version_info[0] < 3:
@overload
def __div__(self, other: timedelta64) -> float: ...
@overload
def __div__(self, other: float) -> timedelta64: ...
@overload
def __truediv__(self, other: timedelta64) -> float: ...
@overload
Expand Down
7 changes: 0 additions & 7 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3868,13 +3868,6 @@ def test_correct_protocol5_error_message(self):
with pytest.raises(ImportError):
array.__reduce_ex__(5)

elif sys.version_info[:2] < (3, 6):
# when calling __reduce_ex__ explicitly with protocol=5 on python
# raise a ValueError saying that protocol 5 is not available for
# this python version
with pytest.raises(ValueError):
array.__reduce_ex__(5)

def test_record_array_with_object_dtype(self):
my_object = object()

Expand Down
46 changes: 8 additions & 38 deletions numpy/lib/npyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,44 +712,14 @@ def _savez(file, args, kwds, compress, allow_pickle=True, pickle_kwargs=None):

zipf = zipfile_factory(file, mode="w", compression=compression)

if sys.version_info >= (3, 6):
# Since Python 3.6 it is possible to write directly to a ZIP file.
for key, val in namedict.items():
fname = key + '.npy'
val = np.asanyarray(val)
# always force zip64, gh-10776
with zipf.open(fname, 'w', force_zip64=True) as fid:
format.write_array(fid, val,
allow_pickle=allow_pickle,
pickle_kwargs=pickle_kwargs)
else:
# Stage arrays in a temporary file on disk, before writing to zip.

# Import deferred for startup time improvement
import tempfile
# Since target file might be big enough to exceed capacity of a global
# temporary directory, create temp file side-by-side with the target file.
file_dir, file_prefix = os.path.split(file) if _is_string_like(file) else (None, 'tmp')
fd, tmpfile = tempfile.mkstemp(prefix=file_prefix, dir=file_dir, suffix='-numpy.npy')
os.close(fd)
try:
for key, val in namedict.items():
fname = key + '.npy'
fid = open(tmpfile, 'wb')
try:
format.write_array(fid, np.asanyarray(val),
allow_pickle=allow_pickle,
pickle_kwargs=pickle_kwargs)
fid.close()
fid = None
zipf.write(tmpfile, arcname=fname)
except IOError as exc:
raise IOError("Failed to write to %s: %s" % (tmpfile, exc))
finally:
if fid:
fid.close()
finally:
os.remove(tmpfile)
for key, val in namedict.items():
fname = key + '.npy'
val = np.asanyarray(val)
# always force zip64, gh-10776
with zipf.open(fname, 'w', force_zip64=True) as fid:
format.write_array(fid, val,
allow_pickle=allow_pickle,
pickle_kwargs=pickle_kwargs)

zipf.close()

Expand Down
2 changes: 0 additions & 2 deletions numpy/ma/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3858,8 +3858,6 @@ def test_varstd(self):
assert_almost_equal(np.sqrt(mXvar0[k]),
mX[:, k].compressed().std())

@pytest.mark.skipif(sys.platform=='win32' and sys.version_info < (3, 6),
reason='Fails on Python < 3.6 on Windows, gh-9671')
@suppress_copy_mask_on_assignment
def test_varstd_specialcases(self):
# Test a special case for var
Expand Down
2 changes: 1 addition & 1 deletion numpy/testing/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ def assert_warn_len_equal(mod, n_in_context, py34=None, py37=None):
if sys.version_info[:2] >= (3, 7):
if py37 is not None:
n_in_context = py37
elif sys.version_info[:2] >= (3, 4):
else:
if py34 is not None:
n_in_context = py34
assert_equal(num_warns, n_in_context)
Expand Down
0