diff --git a/CMakeLists.txt b/CMakeLists.txt index 70f886799ccd..f59c7b999e17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -897,7 +897,7 @@ add_custom_target(mxnet_lint COMMAND ${CMAKE_COMMAND} -DMSVC=${MSVC} -DPYTHON_EX if(BUILD_CYTHON_MODULES) include(cmake/BuildCythonModules.cmake) add_cython_modules(3) # Build cython module for python3 if python3 is found - if((NOT ${PYTHON2_FOUND}) AND (NOT ${PYTHON3_FOUND})) + if(NOT ${PYTHON3_FOUND}) message(FATAL_ERROR "No python interpreter found to build cython modules") endif() endif() diff --git a/amalgamation/python/mxnet_predict.py b/amalgamation/python/mxnet_predict.py index 48e3cd4a5145..4f896846d92f 100644 --- a/amalgamation/python/mxnet_predict.py +++ b/amalgamation/python/mxnet_predict.py @@ -55,46 +55,26 @@ __all__ = ["Predictor", "load_ndarray_file"] -if sys.version_info[0] == 3: - py_str = lambda x: x.decode('utf-8') - def c_str_array(strings): - """Create ctypes const char ** from a list of Python strings. +py_str = lambda x: x.decode('utf-8') - Parameters - ---------- - strings : list of string - Python strings. - Returns - ------- - (ctypes.c_char_p * len(strings)) - A const char ** pointer that can be passed to C API. - """ - arr = (ctypes.c_char_p * len(strings))() - arr[:] = [s.encode('utf-8') for s in strings] - return arr +def c_str_array(strings): + """Create ctypes const char ** from a list of Python strings. + Parameters + ---------- + strings : list of string + Python strings. -else: - py_str = lambda x: x - - def c_str_array(strings): - """Create ctypes const char ** from a list of Python strings. - - Parameters - ---------- - strings : list of strings - Python strings. - - Returns - ------- - (ctypes.c_char_p * len(strings)) - A const char ** pointer that can be passed to C API. - """ - arr = (ctypes.c_char_p * len(strings))() - arr[:] = strings - return arr + Returns + ------- + (ctypes.c_char_p * len(strings)) + A const char ** pointer that can be passed to C API. + """ + arr = (ctypes.c_char_p * len(strings))() + arr[:] = [s.encode('utf-8') for s in strings] + return arr def c_str(string): diff --git a/ci/docker/runtime_functions.sh b/ci/docker/runtime_functions.sh index f123d126562c..8360f88143dd 100755 --- a/ci/docker/runtime_functions.sh +++ b/ci/docker/runtime_functions.sh @@ -43,11 +43,10 @@ scala_prepare() { check_cython() { set -ex - local python_ver=$1 - local is_cython_used=$(python${python_ver} < 2: - # this function is needed for python3 - # to convert ctypes.char_p .value back to python str - py_str = lambda x: x.decode('utf-8') -else: - py_str = lambda x: x +# this function is needed for python3 +# to convert ctypes.char_p .value back to python str +py_str = lambda x: x.decode('utf-8') def data_dir_default(): @@ -78,28 +73,6 @@ def data_dir(): """ return os.getenv('MXNET_HOME', data_dir_default()) -class _Py2CompatibleUnicodeFileWriter(object): - """ - Wraps a file handle decorating the write command to unicode the content before writing. - This makes writing files opened with encoding='utf-8' compatible with Python 2 - """ - - def __init__(self, file_handle): - self._file_handle = file_handle - if sys.version_info[0] > 2: - self.unicode = str - else: - from functools import partial - # pylint: disable=undefined-variable - self.unicode = partial(unicode, encoding="utf-8") - # pylint: enable=undefined-variable - - def write(self, value): - self._file_handle.write(self.unicode(value)) - - def __getattr__(self, name): - return getattr(self._file_handle, name) - class _NullType(object): """Placeholder for arguments""" @@ -404,83 +377,43 @@ def _load_lib(): #---------------------------- # helper function definition #---------------------------- -if sys.version_info[0] < 3: - def c_str(string): - """Create ctypes char * from a Python string. - - Parameters - ---------- - string : string type - Python string. - - Returns - ------- - str : c_char_p - A char pointer that can be passed to C API. - - Examples - -------- - >>> x = mx.base.c_str("Hello, World") - >>> print x.value - Hello, World - """ - return ctypes.c_char_p(string) +def c_str(string): + """Create ctypes char * from a Python string. - def c_str_array(strings): - """Create ctypes const char ** from a list of Python strings. + Parameters + ---------- + string : string type + Python string. - Parameters - ---------- - strings : list of string - Python strings. + Returns + ------- + str : c_char_p + A char pointer that can be passed to C API. - Returns - ------- - (ctypes.c_char_p * len(strings)) - A const char ** pointer that can be passed to C API. - """ - arr = (ctypes.c_char_p * len(strings))() - arr[:] = strings - return arr - -else: - def c_str(string): - """Create ctypes char * from a Python string. - - Parameters - ---------- - string : string type - Python string. - - Returns - ------- - str : c_char_p - A char pointer that can be passed to C API. - - Examples - -------- - >>> x = mx.base.c_str("Hello, World") - >>> print(x.value) - b"Hello, World" - """ - return ctypes.c_char_p(string.encode('utf-8')) + Examples + -------- + >>> x = mx.base.c_str("Hello, World") + >>> print(x.value) + b"Hello, World" + """ + return ctypes.c_char_p(string.encode('utf-8')) - def c_str_array(strings): - """Create ctypes const char ** from a list of Python strings. +def c_str_array(strings): + """Create ctypes const char ** from a list of Python strings. - Parameters - ---------- - strings : list of string - Python strings. + Parameters + ---------- + strings : list of string + Python strings. - Returns - ------- - (ctypes.c_char_p * len(strings)) - A const char ** pointer that can be passed to C API. - """ - arr = (ctypes.c_char_p * len(strings))() - arr[:] = [s.encode('utf-8') for s in strings] - return arr + Returns + ------- + (ctypes.c_char_p * len(strings)) + A const char ** pointer that can be passed to C API. + """ + arr = (ctypes.c_char_p * len(strings))() + arr[:] = [s.encode('utf-8') for s in strings] + return arr def c_array(ctype, values): @@ -821,7 +754,7 @@ def get_module_file(module_name): module_path = module_name.split('.') module_path[-1] = 'gen_' + module_path[-1] file_name = os.path.join(path, '..', *module_path) + '.py' - module_file = _Py2CompatibleUnicodeFileWriter(io.open(file_name, 'w', encoding="utf-8")) + module_file = open(file_name, 'w', encoding="utf-8") dependencies = {'symbol': ['from ._internal import SymbolBase', 'from ..base import _Null'], 'ndarray': ['from ._internal import NDArrayBase', diff --git a/python/mxnet/callback.py b/python/mxnet/callback.py index bfec794f6220..4be509270fd3 100644 --- a/python/mxnet/callback.py +++ b/python/mxnet/callback.py @@ -17,7 +17,6 @@ # coding: utf-8 """Callback functions that can be used to track various status during epoch.""" -from __future__ import absolute_import import logging import math diff --git a/python/mxnet/context.py b/python/mxnet/context.py index 99998eaa28f2..ac9b497396bb 100644 --- a/python/mxnet/context.py +++ b/python/mxnet/context.py @@ -17,7 +17,6 @@ # coding: utf-8 """Context management API of mxnet.""" -from __future__ import absolute_import import threading import warnings import ctypes diff --git a/python/mxnet/contrib/autograd.py b/python/mxnet/contrib/autograd.py index c5c9c027ee24..9c6456cc4bdb 100644 --- a/python/mxnet/contrib/autograd.py +++ b/python/mxnet/contrib/autograd.py @@ -17,8 +17,6 @@ # coding: utf-8 """Autograd for NDArray.""" -from __future__ import absolute_import -from __future__ import division from array import array import ctypes diff --git a/python/mxnet/contrib/io.py b/python/mxnet/contrib/io.py index 3364fcd215d1..7dd71111ebd5 100644 --- a/python/mxnet/contrib/io.py +++ b/python/mxnet/contrib/io.py @@ -17,7 +17,6 @@ # coding: utf-8 """Contrib data iterators for common data formats.""" -from __future__ import absolute_import from ..io import DataIter, DataDesc from .. import ndarray as nd diff --git a/python/mxnet/contrib/onnx/mx2onnx/__init__.py b/python/mxnet/contrib/onnx/mx2onnx/__init__.py index 238174e4a079..779ce86621d6 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/__init__.py +++ b/python/mxnet/contrib/onnx/mx2onnx/__init__.py @@ -17,7 +17,6 @@ # coding: utf-8 """ONNX Export module""" -from __future__ import absolute_import from . import export_model from . import export_onnx diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py index b92797563b1d..65da6a3933da 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py +++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py @@ -51,10 +51,6 @@ Conversion Functions for common layers. Add new functions here with a decorator. """ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals import re import logging diff --git a/python/mxnet/contrib/onnx/mx2onnx/export_model.py b/python/mxnet/contrib/onnx/mx2onnx/export_model.py index 158c24b08fc6..51a62ed46e59 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/export_model.py +++ b/python/mxnet/contrib/onnx/mx2onnx/export_model.py @@ -19,10 +19,6 @@ #pylint: disable-msg=too-many-arguments """Exports an MXNet model to the ONNX model format""" -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals import logging import numpy as np diff --git a/python/mxnet/contrib/onnx/mx2onnx/export_onnx.py b/python/mxnet/contrib/onnx/mx2onnx/export_onnx.py index a7b11fc902db..14aa52b29c6a 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/export_onnx.py +++ b/python/mxnet/contrib/onnx/mx2onnx/export_onnx.py @@ -47,10 +47,6 @@ # pylint: disable=invalid-name,too-many-locals,no-self-use,too-many-arguments, # pylint: disable=maybe-no-member,too-many-nested-blocks """MXNet to ONNX graph converter functions""" -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals import logging import json diff --git a/python/mxnet/contrib/onnx/onnx2mx/_translation_utils.py b/python/mxnet/contrib/onnx/onnx2mx/_translation_utils.py index 0160c5c61974..680c05699c1f 100644 --- a/python/mxnet/contrib/onnx/onnx2mx/_translation_utils.py +++ b/python/mxnet/contrib/onnx/onnx2mx/_translation_utils.py @@ -18,7 +18,6 @@ # coding: utf-8 """Utilities used for translating operators from Onnx to Mxnet.""" # pylint: disable=protected-access -from __future__ import absolute_import as _abs from .... import symbol from .... import module from .... import context diff --git a/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py b/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py index d5071af0763d..72913ddaec4e 100644 --- a/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py +++ b/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=invalid-name,too-many-locals,no-self-use """ Support import export formats.""" -from __future__ import absolute_import as _abs import numpy as np from .... import symbol from .... import ndarray as nd diff --git a/python/mxnet/contrib/quantization.py b/python/mxnet/contrib/quantization.py index 3ceccbf42c6e..0305adb48946 100644 --- a/python/mxnet/contrib/quantization.py +++ b/python/mxnet/contrib/quantization.py @@ -16,7 +16,6 @@ # under the License. """Quantization module for generating quantized (INT8) models from FP32 models.""" -from __future__ import absolute_import try: from scipy import stats diff --git a/python/mxnet/contrib/tensorboard.py b/python/mxnet/contrib/tensorboard.py index 910c26ce32c1..8a4b591b2870 100644 --- a/python/mxnet/contrib/tensorboard.py +++ b/python/mxnet/contrib/tensorboard.py @@ -17,7 +17,6 @@ # coding: utf-8 """TensorBoard functions that can be used to log various status during epoch.""" -from __future__ import absolute_import import logging diff --git a/python/mxnet/contrib/text/_constants.py b/python/mxnet/contrib/text/_constants.py index ef394a976102..110cc059168f 100644 --- a/python/mxnet/contrib/text/_constants.py +++ b/python/mxnet/contrib/text/_constants.py @@ -18,8 +18,6 @@ # coding: utf-8 """Read text files and load embeddings.""" -from __future__ import absolute_import -from __future__ import print_function UNKNOWN_IDX = 0 diff --git a/python/mxnet/contrib/text/embedding.py b/python/mxnet/contrib/text/embedding.py index 979ba2afbeb5..952b664c63ba 100644 --- a/python/mxnet/contrib/text/embedding.py +++ b/python/mxnet/contrib/text/embedding.py @@ -20,10 +20,7 @@ # pylint: disable=super-init-not-called """Text token embeddings.""" -from __future__ import absolute_import -from __future__ import print_function -import io import logging import os import tarfile @@ -257,7 +254,7 @@ def _load_embedding(self, pretrained_file_path, elem_delim, init_unknown_vec, en tokens = set() loaded_unknown_vec = None line_num = 0 - with io.open(pretrained_file_path, 'r', encoding=encoding) as f: + with open(pretrained_file_path, 'r', encoding=encoding) as f: for line in f: line_num += 1 elems = line.rstrip().split(elem_delim) diff --git a/python/mxnet/contrib/text/utils.py b/python/mxnet/contrib/text/utils.py index 88ed75986dce..79cf903edbee 100644 --- a/python/mxnet/contrib/text/utils.py +++ b/python/mxnet/contrib/text/utils.py @@ -18,8 +18,6 @@ # coding: utf-8 """Provide utilities for text data processing.""" -from __future__ import absolute_import -from __future__ import print_function import collections import re diff --git a/python/mxnet/contrib/text/vocab.py b/python/mxnet/contrib/text/vocab.py index 7db3ee844bb5..f034e48d210a 100644 --- a/python/mxnet/contrib/text/vocab.py +++ b/python/mxnet/contrib/text/vocab.py @@ -19,8 +19,6 @@ # pylint: disable=consider-iterating-dictionary """Text token indexer.""" -from __future__ import absolute_import -from __future__ import print_function import collections diff --git a/python/mxnet/cython/ndarray.pyx b/python/mxnet/cython/ndarray.pyx index 8d924e170187..ade6cf42585d 100644 --- a/python/mxnet/cython/ndarray.pyx +++ b/python/mxnet/cython/ndarray.pyx @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License -from __future__ import absolute_import as _abs import sys as _sys import ctypes as _ctypes diff --git a/python/mxnet/cython/symbol.pyx b/python/mxnet/cython/symbol.pyx index 1b42b1e4ff77..778254460287 100644 --- a/python/mxnet/cython/symbol.pyx +++ b/python/mxnet/cython/symbol.pyx @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License -from __future__ import absolute_import as _abs import sys as _sys import ctypes as _ctypes diff --git a/python/mxnet/engine.py b/python/mxnet/engine.py index d4d38f1f292f..6a618b25e369 100644 --- a/python/mxnet/engine.py +++ b/python/mxnet/engine.py @@ -17,7 +17,6 @@ # coding: utf-8 """Engine properties management.""" -from __future__ import absolute_import import ctypes from .base import _LIB, check_call diff --git a/python/mxnet/executor.py b/python/mxnet/executor.py index 3b79f0c8d1b4..3f8fd7331f4e 100644 --- a/python/mxnet/executor.py +++ b/python/mxnet/executor.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=invalid-name, protected-access, too-many-locals, too-many-arguments """Symbolic Executor component of MXNet.""" -from __future__ import absolute_import from array import array as py_array import ctypes diff --git a/python/mxnet/executor_manager.py b/python/mxnet/executor_manager.py index 9a53562204b8..d0b7050b8ad0 100644 --- a/python/mxnet/executor_manager.py +++ b/python/mxnet/executor_manager.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=invalid-name, protected-access, too-many-locals, too-many-arguments, too-many-statements """Executor manager.""" -from __future__ import absolute_import import logging import numpy as np diff --git a/python/mxnet/gluon/contrib/data/text.py b/python/mxnet/gluon/contrib/data/text.py index c0f4a3b924bf..0536ac585484 100644 --- a/python/mxnet/gluon/contrib/data/text.py +++ b/python/mxnet/gluon/contrib/data/text.py @@ -20,7 +20,6 @@ """Text datasets.""" __all__ = ['WikiText2', 'WikiText103'] -import io import os import zipfile import shutil @@ -58,7 +57,7 @@ def _build_vocab(self, content): class _WikiText(_LanguageModelDataset): def _read_batch(self, filename): - with io.open(filename, 'r', encoding='utf8') as fin: + with open(filename, 'r', encoding='utf8') as fin: content = fin.read() self._build_vocab(content) diff --git a/python/mxnet/gluon/data/dataloader.py b/python/mxnet/gluon/data/dataloader.py index 7394f7d5d3d9..d34148417355 100644 --- a/python/mxnet/gluon/data/dataloader.py +++ b/python/mxnet/gluon/data/dataloader.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=ungrouped-imports """Dataset generator.""" -from __future__ import absolute_import __all__ = ['DataLoader'] import pickle @@ -55,10 +54,7 @@ def reduce_ndarray(data): def rebuild_ndarray(pid, fd, shape, dtype): """Rebuild ndarray from pickled shared memory""" # pylint: disable=no-value-for-parameter - if sys.version_info[0] == 2: - fd = multiprocessing.reduction.rebuild_handle(fd) - else: - fd = fd.detach() + fd = fd.detach() return nd.NDArray(nd.ndarray._new_from_shared_mem(pid, fd, shape, dtype)) def reduce_ndarray(data): @@ -66,10 +62,7 @@ def reduce_ndarray(data): # keep a local ref before duplicating fd data = data.as_in_context(context.Context('cpu_shared', 0)) pid, fd, shape, dtype = data._to_shared_mem() - if sys.version_info[0] == 2: - fd = multiprocessing.reduction.reduce_handle(fd) - else: - fd = multiprocessing.reduction.DupFd(fd) + fd = multiprocessing.reduction.DupFd(fd) return rebuild_ndarray, (pid, fd, shape, dtype) ForkingPickler.register(nd.NDArray, reduce_ndarray) @@ -87,10 +80,7 @@ def reduce_np_ndarray(data): def rebuild_np_ndarray(pid, fd, shape, dtype): """Rebuild ndarray from pickled shared memory""" # pylint: disable=no-value-for-parameter - if sys.version_info[0] == 2: - fd = multiprocessing.reduction.rebuild_handle(fd) - else: - fd = fd.detach() + fd = fd.detach() return _mx_np.ndarray(nd.ndarray._new_from_shared_mem(pid, fd, shape, dtype)) def reduce_np_ndarray(data): @@ -98,10 +88,7 @@ def reduce_np_ndarray(data): # keep a local ref before duplicating fd data = data.as_in_context(context.Context('cpu_shared', 0)) pid, fd, shape, dtype = data._to_shared_mem() - if sys.version_info[0] == 2: - fd = multiprocessing.reduction.reduce_handle(fd) - else: - fd = multiprocessing.reduction.DupFd(fd) + fd = multiprocessing.reduction.DupFd(fd) return rebuild_np_ndarray, (pid, fd, shape, dtype) ForkingPickler.register(_mx_np.ndarray, reduce_np_ndarray) @@ -134,11 +121,7 @@ def __getattr__(self, name): class Queue(multiprocessing.queues.Queue): """Wrapper for multiprocessing queue that dumps NDArray with shared memory.""" def __init__(self, *args, **kwargs): - if sys.version_info[0] <= 2: - super(Queue, self).__init__(*args, **kwargs) - else: - super(Queue, self).__init__(*args, ctx=multiprocessing.get_context(), - **kwargs) + super().__init__(*args, ctx=multiprocessing.get_context(), **kwargs) self._reader = ConnectionWrapper(self._reader) self._writer = ConnectionWrapper(self._writer) self._send = self._writer.send @@ -150,11 +133,7 @@ class SimpleQueue(multiprocessing.queues.SimpleQueue): SimpleQueue don't use threading internally. """ def __init__(self, *args, **kwargs): - if sys.version_info[0] <= 2: - super(SimpleQueue, self).__init__(*args, **kwargs) - else: - super(SimpleQueue, self).__init__(*args, ctx=multiprocessing.get_context(), - **kwargs) + super().__init__(*args, ctx=multiprocessing.get_context(), **kwargs) self._reader = ConnectionWrapper(self._reader) self._writer = ConnectionWrapper(self._writer) self._send = self._writer.send @@ -240,7 +219,7 @@ def __init__(self, num_workers, dataset, batchify_fn, batch_sampler, self._batchify_fn = batchify_fn self._batch_sampler = batch_sampler self._key_queue = Queue() - self._data_queue = Queue() if sys.version_info[0] <= 2 else SimpleQueue() + self._data_queue = SimpleQueue() self._data_buffer = {} self._data_buffer_lock = threading.Lock() diff --git a/python/mxnet/gluon/loss.py b/python/mxnet/gluon/loss.py index f6127e4e2373..5dc91a584d2c 100644 --- a/python/mxnet/gluon/loss.py +++ b/python/mxnet/gluon/loss.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=arguments-differ """ losses for training neural networks """ -from __future__ import absolute_import __all__ = ['Loss', 'L2Loss', 'L1Loss', 'SigmoidBinaryCrossEntropyLoss', 'SigmoidBCELoss', 'SoftmaxCrossEntropyLoss', 'SoftmaxCELoss', diff --git a/python/mxnet/gluon/model_zoo/model_store.py b/python/mxnet/gluon/model_zoo/model_store.py index 6da7dd106556..0ab11516fa96 100644 --- a/python/mxnet/gluon/model_zoo/model_store.py +++ b/python/mxnet/gluon/model_zoo/model_store.py @@ -17,7 +17,6 @@ # coding: utf-8 """Model zoo for pre-trained models.""" -from __future__ import print_function __all__ = ['get_model_file', 'purge'] import os import zipfile @@ -27,7 +26,7 @@ import shutil from ..utils import download, check_sha1, replace_file -from ... import base, util +from ... import base _model_sha1 = {name: checksum for checksum, name in [ ('44335d1f0046b328243b32a26a4fbd62d9057b45', 'alexnet'), @@ -104,7 +103,7 @@ def get_model_file(name, root=os.path.join(base.data_dir(), 'models')): else: logging.info('Model file not found. Downloading to %s.', file_path) - util.makedirs(root) + os.makedirs(root, exist_ok=True) repo_url = os.environ.get('MXNET_GLUON_REPO', apache_repo_url) if repo_url[-1] != '/': diff --git a/python/mxnet/gluon/model_zoo/vision/resnet.py b/python/mxnet/gluon/model_zoo/vision/resnet.py index 34e7f595c154..493bb17a969f 100644 --- a/python/mxnet/gluon/model_zoo/vision/resnet.py +++ b/python/mxnet/gluon/model_zoo/vision/resnet.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable= arguments-differ """ResNets, implemented in Gluon.""" -from __future__ import division __all__ = ['ResNetV1', 'ResNetV2', 'BasicBlockV1', 'BasicBlockV2', diff --git a/python/mxnet/gluon/model_zoo/vision/vgg.py b/python/mxnet/gluon/model_zoo/vision/vgg.py index 9a740e633182..8934c16da8e2 100644 --- a/python/mxnet/gluon/model_zoo/vision/vgg.py +++ b/python/mxnet/gluon/model_zoo/vision/vgg.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable= arguments-differ """VGG, implemented in Gluon.""" -from __future__ import division __all__ = ['VGG', 'vgg11', 'vgg13', 'vgg16', 'vgg19', 'vgg11_bn', 'vgg13_bn', 'vgg16_bn', 'vgg19_bn', diff --git a/python/mxnet/gluon/parameter.py b/python/mxnet/gluon/parameter.py index 695565e9cf46..a0f38d76221d 100644 --- a/python/mxnet/gluon/parameter.py +++ b/python/mxnet/gluon/parameter.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=unnecessary-pass, too-many-lines """Neural network parameter.""" -from __future__ import absolute_import __all__ = ['DeferredInitializationError', 'Parameter', 'Constant', 'ParameterDict', 'tensor_types'] diff --git a/python/mxnet/gluon/rnn/rnn_layer.py b/python/mxnet/gluon/rnn/rnn_layer.py index f4489b7656d6..020bfd7afb7f 100644 --- a/python/mxnet/gluon/rnn/rnn_layer.py +++ b/python/mxnet/gluon/rnn/rnn_layer.py @@ -20,7 +20,6 @@ # pylint: disable=too-many-branches, too-many-arguments, no-self-use # pylint: disable=too-many-lines, arguments-differ """Definition of various recurrent neural network layers.""" -from __future__ import print_function import re __all__ = ['RNN', 'LSTM', 'GRU'] diff --git a/python/mxnet/gluon/utils.py b/python/mxnet/gluon/utils.py index 6521472bc41e..51f0a5fd4da9 100644 --- a/python/mxnet/gluon/utils.py +++ b/python/mxnet/gluon/utils.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable= """Parallelization utility optimizer.""" -from __future__ import absolute_import __all__ = ['split_data', 'split_and_load', 'clip_global_norm', 'check_sha1', 'download', 'replace_file'] @@ -35,7 +34,7 @@ import numpy as np from .. import ndarray -from ..util import is_np_shape, is_np_array, makedirs +from ..util import is_np_shape, is_np_array from .. import numpy as _mx_np # pylint: disable=reimported @@ -226,11 +225,9 @@ def replace_file(src, dst): _MOVEFILE_WRITE_THROUGH = 0x8 _windows_default_flags = _MOVEFILE_WRITE_THROUGH - text_type = unicode if sys.version_info[0] == 2 else str # pylint: disable=undefined-variable - def _str_to_unicode(x): """Handle text decoding. Internal use only""" - if not isinstance(x, text_type): + if not isinstance(x, str): return x.decode(sys.getfilesystemencoding()) return x @@ -310,7 +307,7 @@ def download(url, path=None, overwrite=False, sha1_hash=None, retries=5, verify_ if overwrite or not os.path.exists(fname) or (sha1_hash and not check_sha1(fname, sha1_hash)): dirname = os.path.dirname(os.path.abspath(os.path.expanduser(fname))) if not os.path.exists(dirname): - makedirs(dirname) + os.makedirs(dirname, exist_ok=True) while retries + 1 > 0: # Disable pyling too broad Exception # pylint: disable=W0703 diff --git a/python/mxnet/image/detection.py b/python/mxnet/image/detection.py index 0f8d15d2a2a2..52c94684912a 100644 --- a/python/mxnet/image/detection.py +++ b/python/mxnet/image/detection.py @@ -18,7 +18,6 @@ # pylint: disable=unused-import, too-many-lines """Read images and perform augmentations for object detection.""" -from __future__ import absolute_import, print_function import json import logging diff --git a/python/mxnet/image/image.py b/python/mxnet/image/image.py index 95b45af5efd8..8b429a4544f3 100644 --- a/python/mxnet/image/image.py +++ b/python/mxnet/image/image.py @@ -19,7 +19,6 @@ # pylint: disable=too-many-arguments, too-many-locals, no-name-in-module, too-many-branches, too-many-statements """Read individual image files and perform augmentations.""" -from __future__ import absolute_import, print_function import sys import os @@ -202,7 +201,7 @@ def imdecode(buf, *args, **kwargs): """ if not isinstance(buf, nd.NDArray): - if sys.version_info[0] == 3 and not isinstance(buf, (bytes, bytearray, np.ndarray)): + if not isinstance(buf, (bytes, bytearray, np.ndarray)): raise ValueError('buf must be of type bytes, bytearray or numpy.ndarray,' 'if you would like to input type str, please convert to bytes') array_fn = _mx_np.array if is_np_array() else nd.array diff --git a/python/mxnet/initializer.py b/python/mxnet/initializer.py index 5910bf91578e..efec64444af2 100755 --- a/python/mxnet/initializer.py +++ b/python/mxnet/initializer.py @@ -16,7 +16,6 @@ # under the License. """Weight initializer.""" -from __future__ import absolute_import, print_function import re import logging diff --git a/python/mxnet/io/__init__.py b/python/mxnet/io/__init__.py index b053c2f3af6c..d634d72e37f7 100644 --- a/python/mxnet/io/__init__.py +++ b/python/mxnet/io/__init__.py @@ -20,7 +20,6 @@ # coding: utf-8 # pylint: disable=wildcard-import """ Data iterators for common data formats and utility functions.""" -from __future__ import absolute_import from . import io from .io import CSVIter, DataBatch, DataDesc, DataIter, ImageDetRecordIter, ImageRecordInt8Iter, ImageRecordIter,\ diff --git a/python/mxnet/io/io.py b/python/mxnet/io/io.py index e36665e61c42..5a022ea1c81c 100644 --- a/python/mxnet/io/io.py +++ b/python/mxnet/io/io.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=unnecessary-pass """Data iterators for common data formats.""" -from __future__ import absolute_import from collections import namedtuple import sys diff --git a/python/mxnet/kvstore/base.py b/python/mxnet/kvstore/base.py index 6f4433bc7bf3..63d46823a1b7 100644 --- a/python/mxnet/kvstore/base.py +++ b/python/mxnet/kvstore/base.py @@ -17,7 +17,6 @@ # coding: utf-8 """ Key value store interface of MXNet for parameter synchronization.""" -from __future__ import absolute_import from array import array import ctypes diff --git a/python/mxnet/kvstore/kvstore.py b/python/mxnet/kvstore/kvstore.py index 97fda98f0d84..11ec3f98178f 100644 --- a/python/mxnet/kvstore/kvstore.py +++ b/python/mxnet/kvstore/kvstore.py @@ -17,7 +17,6 @@ # coding: utf-8 """ Key value store interface of MXNet for parameter synchronization.""" -from __future__ import absolute_import import pickle import ctypes diff --git a/python/mxnet/kvstore/kvstore_server.py b/python/mxnet/kvstore/kvstore_server.py index 592d2500755f..f7fd5350f744 100644 --- a/python/mxnet/kvstore/kvstore_server.py +++ b/python/mxnet/kvstore/kvstore_server.py @@ -17,7 +17,6 @@ # coding: utf-8 """A server node for the key value store.""" -from __future__ import absolute_import import ctypes import sys import pickle diff --git a/python/mxnet/libinfo.py b/python/mxnet/libinfo.py index 589a69ce60cc..4ee86c315f2e 100644 --- a/python/mxnet/libinfo.py +++ b/python/mxnet/libinfo.py @@ -17,7 +17,6 @@ # coding: utf-8 """Information about mxnet.""" -from __future__ import absolute_import import os import platform import logging diff --git a/python/mxnet/library.py b/python/mxnet/library.py index 8ea0bc2ae0a5..13df2ec71298 100644 --- a/python/mxnet/library.py +++ b/python/mxnet/library.py @@ -17,7 +17,6 @@ # coding: utf-8 """Library management API of mxnet.""" -from __future__ import absolute_import import ctypes import sys import os diff --git a/python/mxnet/log.py b/python/mxnet/log.py index 6dcaedbe6fe7..2b9da024fafa 100644 --- a/python/mxnet/log.py +++ b/python/mxnet/log.py @@ -21,7 +21,6 @@ # pylint: disable= protected-access, invalid-name """Logging utilities.""" import logging -import sys import warnings CRITICAL = logging.CRITICAL @@ -31,8 +30,6 @@ DEBUG = logging.DEBUG NOTSET = logging.NOTSET -PY3 = sys.version_info[0] == 3 - class _Formatter(logging.Formatter): # pylint: disable= no-self-use @@ -71,10 +68,7 @@ def format(self, record): fmt += '%(asctime)s %(process)d %(pathname)s:%(funcName)s:%(lineno)d' fmt += ']\x1b[0m' fmt += ' %(message)s' - if PY3: - self._style._fmt = fmt # pylint: disable= no-member - else: - self._fmt = fmt + self._style._fmt = fmt # pylint: disable= no-member return super(_Formatter, self).format(record) def getLogger(name=None, filename=None, filemode=None, level=WARNING): diff --git a/python/mxnet/metric.py b/python/mxnet/metric.py index d1074c923337..eb8f99a66d48 100644 --- a/python/mxnet/metric.py +++ b/python/mxnet/metric.py @@ -19,7 +19,6 @@ # pylint: disable=no-member, too-many-lines """Online evaluation metric module.""" -from __future__ import absolute_import import math from collections import OrderedDict diff --git a/python/mxnet/model.py b/python/mxnet/model.py index e89a10b345ce..fa247624975d 100644 --- a/python/mxnet/model.py +++ b/python/mxnet/model.py @@ -18,7 +18,6 @@ # pylint: disable=fixme, invalid-name, too-many-arguments, too-many-locals, too-many-lines # pylint: disable=too-many-branches, too-many-statements """MXNet model module""" -from __future__ import absolute_import, print_function import os import time diff --git a/python/mxnet/monitor.py b/python/mxnet/monitor.py index 9eaae07e042e..ce19ad0ca8ac 100644 --- a/python/mxnet/monitor.py +++ b/python/mxnet/monitor.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=protected-access, logging-format-interpolation, invalid-name, no-member, too-many-branches """Monitor outputs, weights, and gradients for debugging.""" -from __future__ import absolute_import import re import ctypes diff --git a/python/mxnet/name.py b/python/mxnet/name.py index 4149d1db2731..b276c72f6ca2 100644 --- a/python/mxnet/name.py +++ b/python/mxnet/name.py @@ -17,7 +17,6 @@ # coding: utf-8 """Automatic naming support for symbolic API.""" -from __future__ import absolute_import import threading import warnings from .base import classproperty, with_metaclass, _MXClassPropertyMetaClass diff --git a/python/mxnet/ndarray/_internal.py b/python/mxnet/ndarray/_internal.py index d48255647939..14142c407fde 100644 --- a/python/mxnet/ndarray/_internal.py +++ b/python/mxnet/ndarray/_internal.py @@ -24,12 +24,9 @@ if int(_os.environ.get("MXNET_ENABLE_CYTHON", True)) == 0: from .._ctypes.ndarray import NDArrayBase, CachedOp from .._ctypes.ndarray import _set_ndarray_class, _imperative_invoke, _set_np_ndarray_class - elif _sys.version_info >= (3, 0): + else: from .._cy3.ndarray import NDArrayBase, CachedOp from .._cy3.ndarray import _set_ndarray_class, _imperative_invoke, _set_np_ndarray_class - else: - from .._cy2.ndarray import NDArrayBase, CachedOp - from .._cy2.ndarray import _set_ndarray_class, _imperative_invoke, _set_np_ndarray_class except ImportError: if int(_os.environ.get("MXNET_ENFORCE_CYTHON", False)) != 0: raise ImportError("Cython Module cannot be loaded but MXNET_ENFORCE_CYTHON=1") diff --git a/python/mxnet/ndarray/contrib.py b/python/mxnet/ndarray/contrib.py index 4bfa97846084..2ff422f29497 100644 --- a/python/mxnet/ndarray/contrib.py +++ b/python/mxnet/ndarray/contrib.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=wildcard-import, unused-wildcard-import,redefined-outer-name """Contrib NDArray API of MXNet.""" -from __future__ import absolute_import import math import numpy as np import mxnet as mx diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py index 9ff034a4eefc..71486f78ab74 100644 --- a/python/mxnet/ndarray/ndarray.py +++ b/python/mxnet/ndarray/ndarray.py @@ -21,7 +21,6 @@ """NDArray API of MXNet.""" -from __future__ import absolute_import, division try: from __builtin__ import slice as py_slice @@ -33,7 +32,6 @@ import warnings import operator from functools import reduce # pylint: disable=redefined-builtin -import sys import numpy as np from ..base import _LIB, numeric_types, integer_types from ..base import c_str, c_array, c_array_buf, c_handle_array, mx_real_t @@ -148,7 +146,7 @@ def _new_alloc_handle(shape, ctx, delay_alloc, dtype=mx_real_t): A new empty `NDArray` handle. """ hdl = NDArrayHandle() - if sys.version_info[0] > 2 and _int64_enabled(): + if _int64_enabled(): check_call(_LIB.MXNDArrayCreateEx64( c_array_buf(mx_int64, native_array('q', shape)), ctypes.c_int(len(shape)), @@ -1035,7 +1033,7 @@ def _get_nd_basic_indexing(self, key): ) handle = NDArrayHandle() flat_self = self.reshape(-1) - if sys.version_info[0] > 2 and _int64_enabled(): + if _int64_enabled(): check_call( _LIB.MXNDArraySlice64( flat_self.handle, @@ -1078,7 +1076,7 @@ def _advanced_index_to_array(idx, ax_len, ctx): The ``ax_len`` is used to convert `slice` objects to integer arrays. """ - if sys.version_info[0] > 2 and _int64_enabled(): + if _int64_enabled(): idx_dtype = 'int64' else: idx_dtype = 'int32' @@ -1093,7 +1091,7 @@ def _advanced_index_to_array(idx, ax_len, ctx): elif isinstance(idx, py_slice): start, stop, step = idx.indices(ax_len) return arange(start, stop, step, ctx=ctx, dtype=idx_dtype) - elif sys.version_info[0] > 2 and isinstance(idx, range): + elif isinstance(idx, range): return arange(idx.start, idx.stop, idx.step, ctx=ctx, dtype=idx_dtype) else: raise RuntimeError('illegal index type {}'.format(type(idx))) @@ -1376,7 +1374,7 @@ def _at(self, idx): if idx < 0: raise IndexError('index %d is out of bounds for axis 0 with size %d' % (idx-length, length)) - if sys.version_info[0] > 2 and _int64_enabled(): + if _int64_enabled(): check_call(_LIB.MXNDArrayAt64( self.handle, ctypes.c_int64(idx), ctypes.byref(handle))) else: @@ -3037,7 +3035,7 @@ def _is_advanced_index(idx): return True elif isinstance(idx, py_slice) or idx is None: return False - elif sys.version_info[0] > 2 and isinstance(idx, range): + elif isinstance(idx, range): return True else: raise RuntimeError('illegal index type {}'.format(type(idx))) @@ -3056,7 +3054,7 @@ def get_indexing_dispatch_code(key): if getattr(idx, 'dtype', None) == np.bool_: num_bools += 1 basic_indexing = False - elif sys.version_info[0] > 2 and isinstance(idx, range): + elif isinstance(idx, range): basic_indexing = False elif not (isinstance(idx, (py_slice, integer_types)) or idx is None): raise ValueError( diff --git a/python/mxnet/ndarray/numpy/_op.py b/python/mxnet/ndarray/numpy/_op.py index 24d3310a5cae..85813fb51a88 100644 --- a/python/mxnet/ndarray/numpy/_op.py +++ b/python/mxnet/ndarray/numpy/_op.py @@ -19,7 +19,6 @@ # pylint: disable=unused-argument """Namespace for numpy operators used in Gluon dispatched by F=ndarray.""" -from __future__ import absolute_import import numpy as _np from ...base import numeric_types, integer_types from ...util import _sanity_check_params, set_module diff --git a/python/mxnet/ndarray/numpy/linalg.py b/python/mxnet/ndarray/numpy/linalg.py index 7716dddb4bc8..0acedf4bbab4 100644 --- a/python/mxnet/ndarray/numpy/linalg.py +++ b/python/mxnet/ndarray/numpy/linalg.py @@ -17,7 +17,6 @@ """Namespace for operators used in Gluon dispatched by F=ndarray.""" -from __future__ import absolute_import from . import _op as _mx_nd_np from . import _internal as _npi diff --git a/python/mxnet/ndarray/numpy/random.py b/python/mxnet/ndarray/numpy/random.py index 089b59e99e83..8a791a56c259 100644 --- a/python/mxnet/ndarray/numpy/random.py +++ b/python/mxnet/ndarray/numpy/random.py @@ -16,7 +16,6 @@ # under the License. """Namespace for operators used in Gluon dispatched by F=ndarray.""" -from __future__ import absolute_import import numpy as np from ...context import current_context from . import _internal as _npi diff --git a/python/mxnet/ndarray/numpy_extension/random.py b/python/mxnet/ndarray/numpy_extension/random.py index 5520a1f1b4d0..8bd17cf092b0 100644 --- a/python/mxnet/ndarray/numpy_extension/random.py +++ b/python/mxnet/ndarray/numpy_extension/random.py @@ -16,7 +16,6 @@ # under the License. """Namespace for operators used in Gluon dispatched by F=ndarray.""" -from __future__ import absolute_import from ...context import current_context from ..numpy import _internal as _npi diff --git a/python/mxnet/ndarray/register.py b/python/mxnet/ndarray/register.py index c2f595aa1c83..06bca0acfd21 100644 --- a/python/mxnet/ndarray/register.py +++ b/python/mxnet/ndarray/register.py @@ -16,7 +16,6 @@ # under the License. """Register backend ops in mxnet.ndarray namespace""" -from __future__ import absolute_import import os as _os import ctypes import numpy as _np # pylint: disable=unused-import diff --git a/python/mxnet/ndarray/sparse.py b/python/mxnet/ndarray/sparse.py index c135a09afb87..b0238e369abc 100644 --- a/python/mxnet/ndarray/sparse.py +++ b/python/mxnet/ndarray/sparse.py @@ -19,8 +19,6 @@ # pylint: disable=wildcard-import, unused-wildcard-import, too-many-lines """Sparse NDArray API of MXNet.""" -from __future__ import absolute_import -from __future__ import division try: from __builtin__ import slice as py_slice from __builtin__ import sum as py_sum diff --git a/python/mxnet/ndarray_doc.py b/python/mxnet/ndarray_doc.py index 20e541f94d0b..b506d2aa1bff 100644 --- a/python/mxnet/ndarray_doc.py +++ b/python/mxnet/ndarray_doc.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=unused-argument, too-many-arguments, unnecessary-pass """Extra symbol documents""" -from __future__ import absolute_import as _abs import re as _re from .base import build_param_doc as _build_param_doc diff --git a/python/mxnet/numpy/__init__.py b/python/mxnet/numpy/__init__.py index 1994148d14d1..0c7ad472c840 100644 --- a/python/mxnet/numpy/__init__.py +++ b/python/mxnet/numpy/__init__.py @@ -17,7 +17,6 @@ """MXNet NumPy module.""" -from __future__ import division, absolute_import, print_function from . import random from . import linalg diff --git a/python/mxnet/numpy/_register.py b/python/mxnet/numpy/_register.py index 8a2d2ea61c24..fbf53988eb0b 100644 --- a/python/mxnet/numpy/_register.py +++ b/python/mxnet/numpy/_register.py @@ -17,7 +17,6 @@ """Registering ops in mxnet.numpy for imperative programming.""" -from __future__ import absolute_import from ..base import _init_np_op_module from ..ndarray.register import _make_ndarray_function diff --git a/python/mxnet/numpy/arrayprint.py b/python/mxnet/numpy/arrayprint.py index 9be7faf1f602..1592dc2b7d4a 100644 --- a/python/mxnet/numpy/arrayprint.py +++ b/python/mxnet/numpy/arrayprint.py @@ -17,7 +17,6 @@ """ndarray print format controller.""" -from __future__ import absolute_import, print_function import numpy as onp from ..util import set_module diff --git a/python/mxnet/numpy/fallback.py b/python/mxnet/numpy/fallback.py index 45f4514250c6..b38baa185d2a 100644 --- a/python/mxnet/numpy/fallback.py +++ b/python/mxnet/numpy/fallback.py @@ -17,7 +17,6 @@ """Operators that fallback to official NumPy implementation.""" -from __future__ import absolute_import import numpy as onp diff --git a/python/mxnet/numpy/fallback_linalg.py b/python/mxnet/numpy/fallback_linalg.py index 09689f5aa7a4..1e48ab636d44 100644 --- a/python/mxnet/numpy/fallback_linalg.py +++ b/python/mxnet/numpy/fallback_linalg.py @@ -17,7 +17,6 @@ """Operators that fallback to official NumPy implementation for np.linalg.""" -from __future__ import absolute_import import numpy as onp diff --git a/python/mxnet/numpy/function_base.py b/python/mxnet/numpy/function_base.py index e8e07c70a167..69052765dda5 100644 --- a/python/mxnet/numpy/function_base.py +++ b/python/mxnet/numpy/function_base.py @@ -16,7 +16,6 @@ # under the License. """Numpy basic functions.""" -from __future__ import absolute_import from .stride_tricks import broadcast_arrays diff --git a/python/mxnet/numpy/io.py b/python/mxnet/numpy/io.py index aece13fa1db4..ce2606740886 100644 --- a/python/mxnet/numpy/io.py +++ b/python/mxnet/numpy/io.py @@ -17,7 +17,6 @@ """I/O functions for ndarrays.""" -from __future__ import absolute_import import numpy as onp from ..context import current_context from .multiarray import array diff --git a/python/mxnet/numpy/linalg.py b/python/mxnet/numpy/linalg.py index 456a4b897bbd..4d0c5b01698e 100644 --- a/python/mxnet/numpy/linalg.py +++ b/python/mxnet/numpy/linalg.py @@ -17,7 +17,6 @@ """Namespace for ops used in imperative programming.""" -from __future__ import absolute_import from ..ndarray import numpy as _mx_nd_np from .fallback_linalg import * # pylint: disable=wildcard-import,unused-wildcard-import from . import fallback_linalg diff --git a/python/mxnet/numpy/multiarray.py b/python/mxnet/numpy/multiarray.py index c3e5fe7d7d54..0ac2812e6be8 100644 --- a/python/mxnet/numpy/multiarray.py +++ b/python/mxnet/numpy/multiarray.py @@ -20,8 +20,6 @@ # pylint: disable=too-many-lines, unused-argument """numpy ndarray and util functions.""" -from __future__ import absolute_import -from __future__ import division try: from __builtin__ import slice as py_slice diff --git a/python/mxnet/numpy/random.py b/python/mxnet/numpy/random.py index ec35468488d0..2ff6b9532189 100644 --- a/python/mxnet/numpy/random.py +++ b/python/mxnet/numpy/random.py @@ -17,7 +17,6 @@ """Namespace for ops used in imperative programming.""" -from __future__ import absolute_import from ..ndarray import numpy as _mx_nd_np diff --git a/python/mxnet/numpy/utils.py b/python/mxnet/numpy/utils.py index 7e4518ad42ce..0a28095c06b9 100644 --- a/python/mxnet/numpy/utils.py +++ b/python/mxnet/numpy/utils.py @@ -18,7 +18,6 @@ """Util functions for the numpy module.""" -from __future__ import absolute_import import numpy as onp diff --git a/python/mxnet/numpy_dispatch_protocol.py b/python/mxnet/numpy_dispatch_protocol.py index 72c4e3af0e50..a507d030529d 100644 --- a/python/mxnet/numpy_dispatch_protocol.py +++ b/python/mxnet/numpy_dispatch_protocol.py @@ -17,7 +17,6 @@ """Utils for registering NumPy array function protocol for mxnet.numpy ops.""" -from __future__ import absolute_import import functools import numpy as _np from . import numpy as mx_np # pylint: disable=reimported diff --git a/python/mxnet/numpy_extension/__init__.py b/python/mxnet/numpy_extension/__init__.py index c4b90f2f8d35..a9e34b1b460b 100644 --- a/python/mxnet/numpy_extension/__init__.py +++ b/python/mxnet/numpy_extension/__init__.py @@ -19,7 +19,6 @@ """Module for ops not belonging to the official numpy package for imperative programming.""" -from __future__ import absolute_import from . import _op from . import image from . import random # pylint: disable=wildcard-import diff --git a/python/mxnet/numpy_extension/_register.py b/python/mxnet/numpy_extension/_register.py index 8abb7254057c..2fa9c8d4e1b6 100644 --- a/python/mxnet/numpy_extension/_register.py +++ b/python/mxnet/numpy_extension/_register.py @@ -17,7 +17,6 @@ """Registering ops in mxnet.numpy_extension for imperative programming.""" -from __future__ import absolute_import from ..base import _init_np_op_module from ..ndarray.register import _make_ndarray_function diff --git a/python/mxnet/numpy_extension/random.py b/python/mxnet/numpy_extension/random.py index 3735abe14d51..35e6eb1f4d19 100644 --- a/python/mxnet/numpy_extension/random.py +++ b/python/mxnet/numpy_extension/random.py @@ -17,7 +17,6 @@ """Namespace for ops used in imperative programming.""" -from __future__ import absolute_import from .. import random as _mx_rand from ..ndarray import numpy_extension as _mx_nd_npx diff --git a/python/mxnet/numpy_extension/utils.py b/python/mxnet/numpy_extension/utils.py index 0aa89badbb58..23d28ea76a15 100644 --- a/python/mxnet/numpy_extension/utils.py +++ b/python/mxnet/numpy_extension/utils.py @@ -18,7 +18,6 @@ """Util functions for the numpy module.""" -from __future__ import absolute_import import ctypes from .. util import is_np_array, is_np_shape diff --git a/python/mxnet/numpy_op_fallback.py b/python/mxnet/numpy_op_fallback.py index 000dc6d4bba1..3503c7a3a278 100644 --- a/python/mxnet/numpy_op_fallback.py +++ b/python/mxnet/numpy_op_fallback.py @@ -17,7 +17,6 @@ """Fallback-to-NumPy operator implementation.""" -from __future__ import absolute_import from distutils.version import StrictVersion import functools import ast diff --git a/python/mxnet/numpy_op_signature.py b/python/mxnet/numpy_op_signature.py index f3226dd66f56..838eee58ffb3 100644 --- a/python/mxnet/numpy_op_signature.py +++ b/python/mxnet/numpy_op_signature.py @@ -17,8 +17,6 @@ """Make builtin ops' signatures compatible with NumPy.""" -import sys -import warnings import inspect from . import _numpy_op_doc from . import numpy as mx_np @@ -54,13 +52,6 @@ def _get_builtin_op(op_name): def _register_op_signatures(): - if sys.version_info.major < 3 or sys.version_info.minor < 5: - warnings.warn('Some mxnet.numpy operator signatures may not be displayed consistently with ' - 'their counterparts in the official NumPy package due to too-low Python ' - 'version {}. Python >= 3.5 is required to make the signatures display correctly.' - .format(str(sys.version))) - return - for op_name in dir(_numpy_op_doc): op = _get_builtin_op(op_name) if op is not None: diff --git a/python/mxnet/operator.py b/python/mxnet/operator.py index 3affa212bfd4..eff732086247 100644 --- a/python/mxnet/operator.py +++ b/python/mxnet/operator.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=invalid-name, protected-access, too-many-arguments, no-self-use, too-many-locals, broad-except, too-many-lines, unnecessary-pass """numpy interface for operators.""" -from __future__ import absolute_import import traceback import warnings diff --git a/python/mxnet/optimizer/optimizer.py b/python/mxnet/optimizer/optimizer.py index 09e881ebfca6..737a947509b0 100755 --- a/python/mxnet/optimizer/optimizer.py +++ b/python/mxnet/optimizer/optimizer.py @@ -18,7 +18,6 @@ # pylint: disable=too-many-lines """Weight updating functions.""" -from __future__ import absolute_import import logging import math import pickle diff --git a/python/mxnet/profiler.py b/python/mxnet/profiler.py index 8e8ac87c9e06..1a12f6fdc182 100644 --- a/python/mxnet/profiler.py +++ b/python/mxnet/profiler.py @@ -19,7 +19,6 @@ # pylint: disable=fixme, invalid-name, too-many-arguments, too-many-locals, too-many-lines # pylint: disable=too-many-branches, too-many-statements """Profiler setting methods.""" -from __future__ import absolute_import import ctypes import warnings from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array, py_str, KVStoreHandle diff --git a/python/mxnet/random.py b/python/mxnet/random.py index 1d6fe27c3d46..5e018d214b24 100644 --- a/python/mxnet/random.py +++ b/python/mxnet/random.py @@ -19,7 +19,6 @@ # pylint: disable=no-member, protected-access, unused-import, no-name-in-module # pylint: disable=wildcard-import, unused-wildcard-import """Random number interface of MXNet.""" -from __future__ import absolute_import import ctypes from .base import _LIB, check_call, integer_types diff --git a/python/mxnet/recordio.py b/python/mxnet/recordio.py index 225df3beb0dc..eb861147b967 100644 --- a/python/mxnet/recordio.py +++ b/python/mxnet/recordio.py @@ -16,7 +16,6 @@ # under the License. """Read and write for the RecordIO data format.""" -from __future__ import absolute_import from collections import namedtuple from multiprocessing import current_process diff --git a/python/mxnet/registry.py b/python/mxnet/registry.py index 0e4ac1c0b8c1..4b1260b075dc 100644 --- a/python/mxnet/registry.py +++ b/python/mxnet/registry.py @@ -19,7 +19,6 @@ # pylint: disable=no-member """Registry for serializable objects.""" -from __future__ import absolute_import import json import warnings diff --git a/python/mxnet/rnn/io.py b/python/mxnet/rnn/io.py index f988500ff927..a10714b85e1e 100644 --- a/python/mxnet/rnn/io.py +++ b/python/mxnet/rnn/io.py @@ -18,7 +18,6 @@ # coding: utf-8 # pylint: disable=too-many-arguments, too-many-locals """Definition of various recurrent neural network cells.""" -from __future__ import print_function import bisect import random diff --git a/python/mxnet/rnn/rnn_cell.py b/python/mxnet/rnn/rnn_cell.py index cc9e6067e9ee..ceb33d7dcf0a 100644 --- a/python/mxnet/rnn/rnn_cell.py +++ b/python/mxnet/rnn/rnn_cell.py @@ -20,7 +20,6 @@ # pylint: disable=too-many-branches, too-many-arguments, no-self-use # pylint: disable=too-many-lines """Definition of various recurrent neural network cells.""" -from __future__ import print_function import warnings import functools diff --git a/python/mxnet/rtc.py b/python/mxnet/rtc.py index 5dfc5ea6dfe2..ada487663866 100644 --- a/python/mxnet/rtc.py +++ b/python/mxnet/rtc.py @@ -16,7 +16,6 @@ # under the License. """Interface to runtime cuda kernel compile module.""" -from __future__ import absolute_import from array import array import re diff --git a/python/mxnet/symbol/_internal.py b/python/mxnet/symbol/_internal.py index d46c0e64e6f1..98e4dc04cc76 100644 --- a/python/mxnet/symbol/_internal.py +++ b/python/mxnet/symbol/_internal.py @@ -26,12 +26,9 @@ if int(_os.environ.get("MXNET_ENABLE_CYTHON", True)) == 0: from .._ctypes.symbol import SymbolBase, _set_symbol_class, _set_np_symbol_class from .._ctypes.symbol import _symbol_creator - elif _sys.version_info >= (3, 0): + else: from .._cy3.symbol import SymbolBase, _set_symbol_class, _set_np_symbol_class from .._cy3.symbol import _symbol_creator - else: - from .._cy2.symbol import SymbolBase, _set_symbol_class, _set_np_symbol_class - from .._cy2.symbol import _symbol_creator except ImportError: if int(_os.environ.get("MXNET_ENFORCE_CYTHON", False)) != 0: raise ImportError("Cython Module cannot be loaded but MXNET_ENFORCE_CYTHON=1") diff --git a/python/mxnet/symbol/numpy/_symbol.py b/python/mxnet/symbol/numpy/_symbol.py index 72d45b12e57a..957e49823eda 100644 --- a/python/mxnet/symbol/numpy/_symbol.py +++ b/python/mxnet/symbol/numpy/_symbol.py @@ -18,7 +18,6 @@ # pylint: disable=too-many-lines, unused-argument """numpy namespace for operators used in Gluon APIs dispatched by F=symbol module.""" -from __future__ import absolute_import import ctypes import numpy as _np from . import _op as _mx_np_op diff --git a/python/mxnet/symbol/numpy/linalg.py b/python/mxnet/symbol/numpy/linalg.py index 83e30bee5962..d326b37f0635 100644 --- a/python/mxnet/symbol/numpy/linalg.py +++ b/python/mxnet/symbol/numpy/linalg.py @@ -17,7 +17,6 @@ """Namespace for operators used in Gluon dispatched by F=symbol.""" -from __future__ import absolute_import from . import _symbol from . import _op as _mx_sym_np from . import _internal as _npi diff --git a/python/mxnet/symbol/numpy/random.py b/python/mxnet/symbol/numpy/random.py index f572e5c8fa4f..fae9c037ded2 100644 --- a/python/mxnet/symbol/numpy/random.py +++ b/python/mxnet/symbol/numpy/random.py @@ -17,7 +17,6 @@ """Namespace for operators used in Gluon dispatched by F=symbol.""" -from __future__ import absolute_import from ...context import current_context from . import _internal as _npi diff --git a/python/mxnet/symbol/numpy_extension/random.py b/python/mxnet/symbol/numpy_extension/random.py index 8d2dc4e03fee..35bc8489c27e 100644 --- a/python/mxnet/symbol/numpy_extension/random.py +++ b/python/mxnet/symbol/numpy_extension/random.py @@ -17,7 +17,6 @@ """Namespace for operators used in Gluon dispatched by F=symbol.""" -from __future__ import absolute_import from ...context import current_context from ..numpy import _internal as _npi diff --git a/python/mxnet/symbol/register.py b/python/mxnet/symbol/register.py index b9950e542016..8e7234a968d3 100644 --- a/python/mxnet/symbol/register.py +++ b/python/mxnet/symbol/register.py @@ -17,7 +17,6 @@ # pylint: disable=unused-import """Register backend ops in mxnet.symbol namespace.""" -from __future__ import absolute_import import os as _os import ctypes import numpy as _np diff --git a/python/mxnet/symbol/symbol.py b/python/mxnet/symbol/symbol.py index c7c45a4be909..c776443b2782 100644 --- a/python/mxnet/symbol/symbol.py +++ b/python/mxnet/symbol/symbol.py @@ -19,7 +19,6 @@ # pylint: disable=invalid-name, protected-access, too-many-arguments, too-many-lines # pylint: disable=import-error, no-name-in-module """Symbolic configuration API of MXNet.""" -from __future__ import absolute_import as _abs try: from __builtin__ import slice as py_slice except ImportError: @@ -29,7 +28,6 @@ import ctypes import warnings from numbers import Number -import sys import numpy as _numpy # pylint: disable=relative-import from ..attribute import AttrScope @@ -1212,7 +1210,7 @@ def _infer_shape_impl(self, partial, *args, **kwargs): aux_shape_size = mx_uint() aux_shape_ndim = ctypes.POINTER(mx_int)() complete = ctypes.c_int() - if sys.version_info[0] > 2 and _int64_enabled(): + if _int64_enabled(): arg_shape_data = ctypes.POINTER(ctypes.POINTER(mx_int64))() out_shape_data = ctypes.POINTER(ctypes.POINTER(mx_int64))() aux_shape_data = ctypes.POINTER(ctypes.POINTER(mx_int64))() @@ -1700,7 +1698,7 @@ def simple_bind(self, ctx, grad_req='write', type_dict=None, stype_dict=None, aux_state_handles = ctypes.POINTER(NDArrayHandle)() try: - if sys.version_info[0] > 2 and _int64_enabled(): + if _int64_enabled(): check_call(_LIB.MXExecutorSimpleBindEx64(self.handle, ctypes.c_int(ctx.device_typeid), ctypes.c_int(ctx.device_id), diff --git a/python/mxnet/symbol_doc.py b/python/mxnet/symbol_doc.py index e59437a3ccbb..408c16f4f1cc 100644 --- a/python/mxnet/symbol_doc.py +++ b/python/mxnet/symbol_doc.py @@ -45,7 +45,6 @@ It should show typical calling examples and behaviors (e.g. maps an input of what shape to an output of what shape). """ -from __future__ import absolute_import as _abs import re as _re from .base import build_param_doc as _build_param_doc diff --git a/python/mxnet/test_utils.py b/python/mxnet/test_utils.py index 62792e540734..0c7a8eebfeae 100755 --- a/python/mxnet/test_utils.py +++ b/python/mxnet/test_utils.py @@ -17,7 +17,6 @@ """Tools for testing.""" # pylint: disable=too-many-lines -from __future__ import absolute_import, print_function, division import time import gzip import struct diff --git a/python/mxnet/torch.py b/python/mxnet/torch.py index fdf8654a488f..295c019166cf 100644 --- a/python/mxnet/torch.py +++ b/python/mxnet/torch.py @@ -18,7 +18,6 @@ # coding: utf-8 """Interface for NDArray functions executed by torch backend. Install Torch and compile with USE_TORCH=1 to use this module.""" -from __future__ import absolute_import import ctypes import sys diff --git a/python/mxnet/util.py b/python/mxnet/util.py index aa9f5241cd5f..54beeb5a875a 100644 --- a/python/mxnet/util.py +++ b/python/mxnet/util.py @@ -17,10 +17,7 @@ """general utility functions""" import ctypes -import os -import sys import functools -import itertools import inspect import threading @@ -39,16 +36,6 @@ _set_np_array_logged = False -def makedirs(d): - """Create directories recursively if they don't exist. os.makedirs(exist_ok=True) is not - available in Python2""" - if sys.version_info[0] < 3: - from distutils.dir_util import mkpath - mkpath(d) - else: - os.makedirs(d, exist_ok=True) # pylint: disable=unexpected-keyword-arg - - def get_gpu_count(): size = ctypes.c_int() check_call(_LIB.MXGetGPUCount(ctypes.byref(size))) @@ -240,17 +227,6 @@ def np_shape(active=True): return _NumpyShapeScope(active) -def wraps_safely(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS): - """This function is safe version of `functools.wraps` in Python2 which skips wrapping functions - for the attributes that do not exist.""" - if sys.version_info[0] > 2: - return functools.wraps(wrapped) - else: - return functools.wraps(wrapped, - assigned=itertools.ifilter( - functools.partial(hasattr, wrapped), assigned)) - - def use_np_shape(func): """A decorator wrapping a function or class with activated NumPy-shape semantics. When `func` is a function, this ensures that the execution of the function is scoped with NumPy @@ -315,7 +291,7 @@ def value(self): setattr(func, name, use_np_shape(method)) return func elif callable(func): - @wraps_safely(func) + @functools.wraps(func) def _with_np_shape(*args, **kwargs): with np_shape(active=True): return func(*args, **kwargs) @@ -499,7 +475,7 @@ def hybrid_forward(self, F, x, w): setattr(func, name, use_np_array(method)) return func elif callable(func): - @wraps_safely(func) + @functools.wraps(func) def _with_np_array(*args, **kwargs): with np_array(active=True): return func(*args, **kwargs) @@ -620,7 +596,7 @@ def wrap_np_unary_func(func): Function A function wrapped with proper error handling. """ - @wraps_safely(func) + @functools.wraps(func) def _wrap_np_unary_func(x, out=None, **kwargs): if len(kwargs) != 0: for key, value in kwargs.items(): @@ -653,7 +629,7 @@ def wrap_np_binary_func(func): Function A function wrapped with proper error handling. """ - @wraps_safely(func) + @functools.wraps(func) def _wrap_np_binary_func(x1, x2, out=None, **kwargs): if len(kwargs) != 0: for key, value in kwargs.items(): diff --git a/python/mxnet/visualization.py b/python/mxnet/visualization.py index bc8309a4a6ba..346140da8e31 100644 --- a/python/mxnet/visualization.py +++ b/python/mxnet/visualization.py @@ -21,7 +21,6 @@ # pylint: disable=too-many-arguments # pylint: disable=dangerous-default-value """Visualization module""" -from __future__ import absolute_import import re import copy diff --git a/python/setup.py b/python/setup.py index e8545a5c7a90..ab1ff6950277 100644 --- a/python/setup.py +++ b/python/setup.py @@ -70,10 +70,7 @@ def config_cython(): try: from Cython.Build import cythonize - if sys.version_info >= (3, 0): - subdir = "_cy3" - else: - subdir = "_cy2" + subdir = "_cy3" ret = [] path = "mxnet/cython" if os.name == 'nt': diff --git a/tests/python/unittest/test_gluon_estimator.py b/tests/python/unittest/test_gluon_estimator.py index ca61e4b40caa..2c00b1609112 100644 --- a/tests/python/unittest/test_gluon_estimator.py +++ b/tests/python/unittest/test_gluon_estimator.py @@ -118,7 +118,6 @@ def test_validation(): epochs=num_epochs) -@unittest.skipIf(sys.version_info.major < 3, 'Test on python 3') def test_initializer(): ''' test with no initializer, inconsistent initializer ''' net = _get_test_network() @@ -159,7 +158,6 @@ def test_initializer(): epochs=num_epochs) -@unittest.skipIf(sys.version_info.major < 3, 'Test on python 3') def test_trainer(): ''' test with no trainer and invalid trainer ''' net = _get_test_network() @@ -324,7 +322,6 @@ def train_end(self): assert len(train_end) == 2 -@unittest.skipIf(sys.version_info.major < 3, 'Test on python 3') def test_default_handlers(): net = _get_test_network() train_data, _ = _get_test_data() diff --git a/tests/python/unittest/test_numpy_interoperability.py b/tests/python/unittest/test_numpy_interoperability.py index 3c92c051b6b3..7925aa1a1483 100644 --- a/tests/python/unittest/test_numpy_interoperability.py +++ b/tests/python/unittest/test_numpy_interoperability.py @@ -2184,7 +2184,6 @@ def test_np_array_ufunc_protocol(): check_interoperability(_NUMPY_ARRAY_UFUNC_LIST) -@unittest.skipIf(sys.version_info.major < 3, "Skip running fallback ops for Python2") @with_seed() @use_np def test_np_fallback_ops(): diff --git a/tests/python/unittest/test_numpy_op.py b/tests/python/unittest/test_numpy_op.py index 637d07834d24..1d8c8340fca2 100644 --- a/tests/python/unittest/test_numpy_op.py +++ b/tests/python/unittest/test_numpy_op.py @@ -3766,8 +3766,6 @@ def _test_random_beta_range(output): data = np.array([1]) for [param_shape, in_dtype, out_dtype, hybridize] in itertools.product(shape_list, dtype_list, dtype_list, hybridize_list): - if sys.version_info.major < 3 and param_shape == (): - continue mx_data = data.astype(in_dtype) np_data = mx_data.asnumpy() test_random_beta = TestRandomBeta(size=param_shape, dtype=out_dtype) @@ -6293,8 +6291,6 @@ def check_output_n_grad(data_shape, idx_shape, axis, mode): check_output_n_grad(config[0], config[1], config[2], mode) -@unittest.skipUnless(sys.version_info.major >= 3 and sys.version_info.minor >= 5, - 'inspect package requires Python >= 3.5 to work properly') @with_seed() def test_np_builtin_op_signature(): import inspect diff --git a/tests/python/unittest/test_recordio.py b/tests/python/unittest/test_recordio.py index 9edf9b459f74..81561b987839 100644 --- a/tests/python/unittest/test_recordio.py +++ b/tests/python/unittest/test_recordio.py @@ -31,19 +31,13 @@ def test_recordio(): writer = mx.recordio.MXRecordIO(frec, 'w') for i in range(N): - if sys.version_info[0] < 3: - writer.write(str(chr(i))) - else: - writer.write(bytes(str(chr(i)), 'utf-8')) + writer.write(bytes(str(chr(i)), 'utf-8')) del writer reader = mx.recordio.MXRecordIO(frec, 'r') for i in range(N): res = reader.read() - if sys.version_info[0] < 3: - assert res == str(chr(i)) - else: - assert res == bytes(str(chr(i)), 'utf-8') + assert res == bytes(str(chr(i)), 'utf-8') @with_seed() def test_indexed_recordio(): @@ -53,10 +47,7 @@ def test_indexed_recordio(): writer = mx.recordio.MXIndexedRecordIO(fidx, frec, 'w') for i in range(N): - if sys.version_info[0] < 3: - writer.write_idx(i, str(chr(i))) - else: - writer.write_idx(i, bytes(str(chr(i)), 'utf-8')) + writer.write_idx(i, bytes(str(chr(i)), 'utf-8')) del writer reader = mx.recordio.MXIndexedRecordIO(fidx, frec, 'r') @@ -65,10 +56,7 @@ def test_indexed_recordio(): random.shuffle(keys) for i in keys: res = reader.read_idx(i) - if sys.version_info[0] < 3: - assert res == str(chr(i)) - else: - assert res == bytes(str(chr(i)), 'utf-8') + assert res == bytes(str(chr(i)), 'utf-8') @with_seed() def test_recordio_pack_label(): diff --git a/tests/utils/notebook_test/__init__.py b/tests/utils/notebook_test/__init__.py index 3cbc8211b17f..9ee11db428b5 100644 --- a/tests/utils/notebook_test/__init__.py +++ b/tests/utils/notebook_test/__init__.py @@ -109,7 +109,7 @@ def run_notebook(notebook, notebook_dir, kernel=None, no_cache=False, temp_dir=' if notebook is not None: output_file = os.path.join(working_dir, "output.txt") nbformat.write(notebook, output_file) - output_nb = io.open(output_file, mode='r', encoding='utf-8') + output_nb = open(output_file, mode='r', encoding='utf-8') for line in output_nb: if "Warning:" in line and "numpy operator signatures" not in line: errors.append("Warning:\n" + line) diff --git a/tools/ipynb2md.py b/tools/ipynb2md.py index 3708e81b51a7..eba40432e4b9 100755 --- a/tools/ipynb2md.py +++ b/tools/ipynb2md.py @@ -41,12 +41,12 @@ def remove_outputs(nb): def clear_notebook(old_ipynb, new_ipynb): - with io.open(old_ipynb, 'r') as f: + with open(old_ipynb, 'r') as f: nb = nbformat.read(f, nbformat.NO_CONVERT) remove_outputs(nb) - with io.open(new_ipynb, 'w', encoding='utf8') as f: + with open(new_ipynb, 'w', encoding='utf8') as f: nbformat.write(nb, f, nbformat.NO_CONVERT)