diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index d7f272616507..eae5b65263a4 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -23,6 +23,7 @@ from typing import ( Sequence, Sized, SupportsAbs, + SupportsBytes, SupportsComplex, SupportsFloat, SupportsInt, @@ -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: @@ -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: ... @@ -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): ... @@ -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: ... @@ -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 diff --git a/numpy/core/src/multiarray/alloc.c b/numpy/core/src/multiarray/alloc.c index 795fc731564b..887deff53457 100644 --- a/numpy/core/src/multiarray/alloc.c +++ b/numpy/core/src/multiarray/alloc.c @@ -2,17 +2,12 @@ #include #include "structmember.h" -#if PY_VERSION_HEX >= 0x03060000 #include /* public api in 3.7 */ #if PY_VERSION_HEX < 0x03070000 #define PyTraceMalloc_Track _PyTraceMalloc_Track #define PyTraceMalloc_Untrack _PyTraceMalloc_Untrack #endif -#else -#define PyTraceMalloc_Track(...) -#define PyTraceMalloc_Untrack(...) -#endif #define NPY_NO_DEPRECATED_API NPY_API_VERSION #define _MULTIARRAYMODULE diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index d2e8ba06e925..f7cb2185b5b0 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -1763,7 +1763,7 @@ array_reduce_ex_picklebuffer(PyArrayObject *self, int protocol) #if PY_VERSION_HEX >= 0x03080000 /* we expect protocol 5 to be available in Python 3.8 */ pickle_module = PyImport_ImportModule("pickle"); -#elif PY_VERSION_HEX >= 0x03060000 +#else pickle_module = PyImport_ImportModule("pickle5"); if (pickle_module == NULL) { /* for protocol 5, raise a clear ImportError if pickle5 is not found @@ -1772,10 +1772,6 @@ array_reduce_ex_picklebuffer(PyArrayObject *self, int protocol) "requires the pickle5 module for Python >=3.6 and <3.8"); return NULL; } -#else - PyErr_SetString(PyExc_ValueError, "pickle protocol 5 is not available " - "for Python < 3.6"); - return NULL; #endif if (pickle_module == NULL){ return NULL; diff --git a/numpy/core/src/multiarray/temp_elide.c b/numpy/core/src/multiarray/temp_elide.c index 09b94821897a..b19dee418821 100644 --- a/numpy/core/src/multiarray/temp_elide.c +++ b/numpy/core/src/multiarray/temp_elide.c @@ -62,12 +62,8 @@ #define NPY_ELIDE_DEBUG 0 #define NPY_MAX_STACKSIZE 10 -#if PY_VERSION_HEX >= 0x03060000 /* TODO can pep523 be used to somehow? */ #define PYFRAMEEVAL_FUNC "_PyEval_EvalFrameDefault" -#else -#define PYFRAMEEVAL_FUNC "PyEval_EvalFrameEx" -#endif /* * Heuristic size of the array in bytes at which backtrace overhead generation * becomes less than speed gained by in-place operations. Depends on stack depth diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index a701de7c1a54..787255be7afc 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -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() diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index cc3465cc6951..e0a288980801 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -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() diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 27f14a5e72a4..0ed2971e6bd2 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -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 diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 6a6cc664a3cc..c3b9e04b693f 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -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)