diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-04-11 14:31:52 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-04-13 07:43:56 -0600 |
commit | 7f5af37e26ba2e99ad3ee6928b78437f601e96e0 (patch) | |
tree | 1b210bb7361ce691e781884bf06f89c7ebd13360 /numpy | |
parent | 74b08b3f0284d9d2dd55a15dd98a3846913b1b51 (diff) | |
download | numpy-7f5af37e26ba2e99ad3ee6928b78437f601e96e0.tar.gz |
2to3: Apply the `numliterals` fixer and skip the `long` fixer.
The numliterals fixer replaces the old style octal number like '01' by
'0o1' removes the 'L' suffix.
Octal values were previously mistakenly specified in some dates, those
uses have been corrected by removing the leading zeros.
Simply Removing the 'L' suffix should not be a problem, but in some
testing code it looks neccesary, so in those places the Python long
constructor is used instead.
The 'long' type is no longer defined in Python 3. Because we need to
have it defined for Python 2 it is added to numpy/compat/np3k.py where
it is defined as 'int' for Python 3 and 'long' for Python 2. The `long`
fixer then needs to be skipped so that it doesn't undo the good work.
Closes #3074, #3067.
Diffstat (limited to 'numpy')
28 files changed, 75 insertions, 55 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index 871a10afb..0689bc08a 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -159,13 +159,14 @@ else: from . import ma from . import matrixlib as _mat from .matrixlib import * + from .compat import long # Make these accessible from numpy name-space # but not imported in from numpy import * if sys.version_info[0] >= 3: - from builtins import bool, int, long, float, complex, object, unicode, str + from builtins import bool, int, float, complex, object, unicode, str else: - from __builtin__ import bool, int, long, float, complex, object, unicode, str + from __builtin__ import bool, int, float, complex, object, unicode, str from .core import round, abs, max, min diff --git a/numpy/compat/py3k.py b/numpy/compat/py3k.py index 4a7866a56..f45a9973f 100644 --- a/numpy/compat/py3k.py +++ b/numpy/compat/py3k.py @@ -6,12 +6,14 @@ from __future__ import division, absolute_import, print_function __all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception', 'strchar', 'unicode', 'asunicode', 'asbytes_nested', 'asunicode_nested', - 'asstr', 'open_latin1'] + 'asstr', 'open_latin1', 'long'] import sys if sys.version_info[0] >= 3: import io + long = int + integer_types = (int,) bytes = bytes unicode = str @@ -38,13 +40,17 @@ if sys.version_info[0] >= 3: strchar = 'U' + else: bytes = str unicode = unicode + long = long + integer_types = (int, long) asbytes = str asstr = str strchar = 'S' + def isfileobj(f): return isinstance(f, file) @@ -56,6 +62,7 @@ else: def open_latin1(filename, mode='r'): return open(filename, mode=mode) + def getexception(): return sys.exc_info()[1] diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py index d5acb1e97..874a295ef 100644 --- a/numpy/core/defchararray.py +++ b/numpy/core/defchararray.py @@ -22,7 +22,7 @@ from .numerictypes import string_, unicode_, integer, object_, bool_, character from .numeric import ndarray, compare_chararrays from .numeric import array as narray from numpy.core.multiarray import _vec_string -from numpy.compat import asbytes +from numpy.compat import asbytes, long import numpy __all__ = ['chararray', diff --git a/numpy/core/getlimits.py b/numpy/core/getlimits.py index 57ad60543..93210a23b 100644 --- a/numpy/core/getlimits.py +++ b/numpy/core/getlimits.py @@ -260,7 +260,7 @@ class iinfo(object): try: val = iinfo._min_vals[self.key] except KeyError: - val = int(-(1L << (self.bits-1))) + val = int(-(1 << (self.bits-1))) iinfo._min_vals[self.key] = val return val @@ -272,9 +272,9 @@ class iinfo(object): val = iinfo._max_vals[self.key] except KeyError: if self.kind == 'u': - val = int((1L << self.bits) - 1) + val = int((1 << self.bits) - 1) else: - val = int((1L << (self.bits-1)) - 1) + val = int((1 << (self.bits-1)) - 1) iinfo._max_vals[self.key] = val return val diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index ee079157d..0ac153a74 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -3,10 +3,11 @@ from __future__ import division, absolute_import, print_function __all__ = ['memmap'] import warnings -from .numeric import uint8, ndarray, dtype import sys import numpy as np +from .numeric import uint8, ndarray, dtype +from numpy.compat import long dtypedescr = dtype valid_filemodes = ["r", "c", "r+", "w+"] diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 65f0943c8..e164427af 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -90,26 +90,22 @@ __all__ = ['sctypeDict', 'sctypeNA', 'typeDict', 'typeNA', 'sctypes', 'busday_offset', 'busday_count', 'is_busday', 'busdaycalendar', ] -from numpy.core.multiarray import typeinfo, ndarray, array, \ - empty, dtype, datetime_data, datetime_as_string, \ - busday_offset, busday_count, is_busday, busdaycalendar +from numpy.core.multiarray import ( + typeinfo, ndarray, array, empty, dtype, datetime_data, + datetime_as_string, busday_offset, busday_count, is_busday, + busdaycalendar + ) import types as _types import sys +from numpy.compat import bytes, long # we don't export these for import *, but we do want them accessible # as numerictypes.bool, etc. if sys.version_info[0] >= 3: - from builtins import bool, int, long, float, complex, object, unicode, str + from builtins import bool, int, float, complex, object, unicode, str else: - from __builtin__ import bool, int, long, float, complex, object, unicode, str + from __builtin__ import bool, int, float, complex, object, unicode, str -from numpy.compat import bytes - -if sys.version_info[0] >= 3: - # Py3K - class long(int): - # Placeholder class -- this will not escape outside numerictypes.py - pass # String-handling utilities to avoid locale-dependence. @@ -861,7 +857,7 @@ try: _types.StringType, _types.UnicodeType, _types.BufferType] except AttributeError: # Py3K - ScalarType = [int, float, complex, long, bool, bytes, str, memoryview] + ScalarType = [int, float, complex, int, bool, bytes, str, memoryview] ScalarType.extend(_sctype2char_dict.keys()) ScalarType = tuple(ScalarType) diff --git a/numpy/core/records.py b/numpy/core/records.py index b263adb6a..4f520ae66 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -46,7 +46,7 @@ import types import os import sys -from numpy.compat import isfileobj, bytes +from numpy.compat import isfileobj, bytes, long ndarray = sb.ndarray diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index fe2185833..d22868999 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -17,7 +17,7 @@ from numpy.testing import ( assert_raises, assert_warns, dec ) from numpy.testing.utils import _assert_valid_refcount, WarningManager -from numpy.compat import asbytes, asunicode, asbytes_nested +from numpy.compat import asbytes, asunicode, asbytes_nested, long rlevel = 1 diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py index 1f261375f..8cbcfede3 100644 --- a/numpy/core/tests/test_shape_base.py +++ b/numpy/core/tests/test_shape_base.py @@ -6,6 +6,7 @@ from numpy.testing import (TestCase, assert_, assert_raises, assert_array_equal, assert_equal, run_module_suite) from numpy.core import (array, arange, atleast_1d, atleast_2d, atleast_3d, vstack, hstack, newaxis, concatenate) +from numpy.compat import long class TestAtleast1d(TestCase): def test_0D_array(self): @@ -43,7 +44,7 @@ class TestAtleast1d(TestCase): """ assert_(atleast_1d(3).shape == (1,)) assert_(atleast_1d(3j).shape == (1,)) - assert_(atleast_1d(3L).shape == (1,)) + assert_(atleast_1d(long(3)).shape == (1,)) assert_(atleast_1d(3.0).shape == (1,)) assert_(atleast_1d([[2,3],[4,5]]).shape == (2,2)) diff --git a/numpy/f2py/tests/test_return_complex.py b/numpy/f2py/tests/test_return_complex.py index afbe2a4f2..f03416648 100644 --- a/numpy/f2py/tests/test_return_complex.py +++ b/numpy/f2py/tests/test_return_complex.py @@ -2,6 +2,7 @@ from __future__ import division, absolute_import, print_function from numpy.testing import * from numpy import array +from numpy.compat import long import util class TestReturnComplex(util.F2PyTest): @@ -13,7 +14,7 @@ class TestReturnComplex(util.F2PyTest): err = 0.0 assert_( abs(t(234j)-234.0j)<=err) assert_( abs(t(234.6)-234.6)<=err) - assert_( abs(t(234l)-234.0)<=err) + assert_( abs(t(long(234))-234.0)<=err) assert_( abs(t(234.6+3j)-(234.6+3j))<=err) #assert_( abs(t('234')-234.)<=err) #assert_( abs(t('234.6')-234.6)<=err) @@ -44,7 +45,7 @@ class TestReturnComplex(util.F2PyTest): assert_raises(TypeError, t, {}) try: - r = t(10l**400) + r = t(10**400) assert_( repr(r) in ['(inf+0j)','(Infinity+0j)'],repr(r)) except OverflowError: pass diff --git a/numpy/f2py/tests/test_return_integer.py b/numpy/f2py/tests/test_return_integer.py index 81ad4960b..d19653f4d 100644 --- a/numpy/f2py/tests/test_return_integer.py +++ b/numpy/f2py/tests/test_return_integer.py @@ -2,13 +2,14 @@ from __future__ import division, absolute_import, print_function from numpy.testing import * from numpy import array +from numpy.compat import long import util class TestReturnInteger(util.F2PyTest): def check_function(self, t): assert_( t(123)==123,repr(t(123))) assert_( t(123.6)==123) - assert_( t(123l)==123) + assert_( t(long(123))==123) assert_( t('123')==123) assert_( t(-123)==-123) assert_( t([123])==123) @@ -34,7 +35,7 @@ class TestReturnInteger(util.F2PyTest): assert_raises(Exception, t, {}) if t.__doc__.split()[0] in ['t8','s8']: - assert_raises(OverflowError, t, 100000000000000000000000l) + assert_raises(OverflowError, t, 100000000000000000000000) assert_raises(OverflowError, t, 10000000011111111111111.23) class TestF77ReturnInteger(TestReturnInteger): diff --git a/numpy/f2py/tests/test_return_logical.py b/numpy/f2py/tests/test_return_logical.py index 43764a558..3823e5642 100644 --- a/numpy/f2py/tests/test_return_logical.py +++ b/numpy/f2py/tests/test_return_logical.py @@ -2,6 +2,7 @@ from __future__ import division, absolute_import, print_function from numpy.testing import * from numpy import array +from numpy.compat import long import util class TestReturnLogical(util.F2PyTest): @@ -15,7 +16,7 @@ class TestReturnLogical(util.F2PyTest): assert_( t(1j)==1) assert_( t(234)==1) assert_( t(234.6)==1) - assert_( t(234l)==1) + assert_( t(long(234))==1) assert_( t(234.6+3j)==1) assert_( t('234')==1) assert_( t('aaa')==1) @@ -25,7 +26,7 @@ class TestReturnLogical(util.F2PyTest): assert_( t({})==0) assert_( t(t)==1) assert_( t(-234)==1) - assert_( t(10l**100)==1) + assert_( t(10**100)==1) assert_( t([234])==1) assert_( t((234,))==1) assert_( t(array(234))==1) diff --git a/numpy/f2py/tests/test_return_real.py b/numpy/f2py/tests/test_return_real.py index e741e9581..3286e11f2 100644 --- a/numpy/f2py/tests/test_return_real.py +++ b/numpy/f2py/tests/test_return_real.py @@ -2,6 +2,7 @@ from __future__ import division, absolute_import, print_function from numpy.testing import * from numpy import array +from numpy.compat import long import math import util @@ -13,7 +14,7 @@ class TestReturnReal(util.F2PyTest): err = 0.0 assert_( abs(t(234)-234.0)<=err) assert_( abs(t(234.6)-234.6)<=err) - assert_( abs(t(234l)-234.0)<=err) + assert_( abs(t(long(234))-234.0)<=err) assert_( abs(t('234')-234)<=err) assert_( abs(t('234.6')-234.6)<=err) assert_( abs(t(-234)+234)<=err) @@ -42,7 +43,7 @@ class TestReturnReal(util.F2PyTest): assert_raises(Exception, t, {}) try: - r = t(10l**400) + r = t(10**400) assert_( repr(r) in ['inf','Infinity'],repr(r)) except OverflowError: pass diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index 9eaf4d78f..dc143415e 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -10,11 +10,11 @@ import numpy as np import numpy.core.numeric as nx if sys.version_info[0] >= 3: - from builtins import bool, int, long, float, complex, object, unicode, str + from builtins import bool, int, float, complex, object, unicode, str else: - from __builtin__ import bool, int, long, float, complex, object, unicode, str + from __builtin__ import bool, int, float, complex, object, unicode, str -from numpy.compat import asbytes, bytes, asbytes_nested +from numpy.compat import asbytes, bytes, asbytes_nested, long if sys.version_info[0] >= 3: def _bytes_to_complex(s): diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py index 8a7c3a067..112a8dae9 100644 --- a/numpy/lib/arraypad.py +++ b/numpy/lib/arraypad.py @@ -6,6 +6,7 @@ of an n-dimensional array. from __future__ import division, absolute_import, print_function import numpy as np +from numpy.compat import long __all__ = ['pad'] diff --git a/numpy/lib/arrayterator.py b/numpy/lib/arrayterator.py index 761d63749..094d41c11 100644 --- a/numpy/lib/arrayterator.py +++ b/numpy/lib/arrayterator.py @@ -9,12 +9,14 @@ a user-specified number of elements. """ from __future__ import division, absolute_import, print_function +import sys from operator import mul +from functools import reduce + +from numpy.compat import long __all__ = ['Arrayterator'] -import sys -from functools import reduce class Arrayterator(object): """ diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 886ba45b3..17f3463ad 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -139,7 +139,7 @@ from __future__ import division, absolute_import, print_function import numpy import sys from numpy.lib.utils import safe_eval -from numpy.compat import asbytes, isfileobj +from numpy.compat import asbytes, isfileobj, long if sys.version_info[0] >= 3: import pickle diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 43bd3af8b..399f761ba 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -32,6 +32,7 @@ from .utils import deprecate from ._compiled_base import add_newdoc_ufunc import numpy as np import collections +from numpy.compat import long # Force range to be a generator, for np.delete's usage. if sys.version_info[0] < 3: diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py index beb252186..3933fdcde 100644 --- a/numpy/lib/tests/test__datasource.py +++ b/numpy/lib/tests/test__datasource.py @@ -305,7 +305,7 @@ class TestRepositoryExists(TestCase): # would do. scheme, netloc, upath, pms, qry, frg = urlparse(localfile) local_path = os.path.join(self.repos._destpath, netloc) - os.mkdir(local_path, 0700) + os.mkdir(local_path, 0o0700) tmpfile = valid_textfile(local_path) assert_(self.repos.exists(tmpfile)) diff --git a/numpy/lib/tests/test__iotools.py b/numpy/lib/tests/test__iotools.py index 63d0ac2ef..421616ccd 100644 --- a/numpy/lib/tests/test__iotools.py +++ b/numpy/lib/tests/test__iotools.py @@ -175,11 +175,11 @@ class TestStringConverter(TestCase): StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1)) convert = StringConverter(dateparser, date(2000, 1, 1)) test = convert(asbytes('2001-01-01')) - assert_equal(test, date(2001, 01, 01)) + assert_equal(test, date(2001, 1, 1)) test = convert(asbytes('2009-01-01')) - assert_equal(test, date(2009, 01, 01)) + assert_equal(test, date(2009, 1, 1)) test = convert(asbytes('')) - assert_equal(test, date(2000, 01, 01)) + assert_equal(test, date(2000, 1, 1)) # def test_string_to_object(self): "Make sure that string-to-object functions are properly recognized" diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index ae68be41f..ca329aae6 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -9,6 +9,7 @@ from numpy.testing import ( ) from numpy.random import rand from numpy.lib import * +from numpy.compat import long class TestAny(TestCase): diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py index 280d0b174..25e697924 100644 --- a/numpy/lib/tests/test_type_check.py +++ b/numpy/lib/tests/test_type_check.py @@ -3,7 +3,7 @@ from __future__ import division, absolute_import, print_function from numpy.testing import * from numpy.lib import * from numpy.core import * -from numpy.compat import asbytes +from numpy.compat import asbytes, long try: import ctypes @@ -87,7 +87,7 @@ class TestIsscalar(TestCase): assert_(not isscalar([3])) assert_(not isscalar((3,))) assert_(isscalar(3j)) - assert_(isscalar(10L)) + assert_(isscalar(long(10))) assert_(isscalar(4.0)) diff --git a/numpy/lib/user_array.py b/numpy/lib/user_array.py index 1cc1345aa..d675d3702 100644 --- a/numpy/lib/user_array.py +++ b/numpy/lib/user_array.py @@ -6,10 +6,13 @@ complete. """ from __future__ import division, absolute_import, print_function -from numpy.core import array, asarray, absolute, add, subtract, multiply, \ - divide, remainder, power, left_shift, right_shift, bitwise_and, \ - bitwise_or, bitwise_xor, invert, less, less_equal, not_equal, equal, \ - greater, greater_equal, shape, reshape, arange, sin, sqrt, transpose +from numpy.core import ( + array, asarray, absolute, add, subtract, multiply, divide, + remainder, power, left_shift, right_shift, bitwise_and, bitwise_or, + bitwise_xor, invert, less, less_equal, not_equal, equal, greater, + greater_equal, shape, reshape, arange, sin, sqrt, transpose + ) +from numpy.compat import long class container(object): def __init__(self, data, dtype=None, copy=True): diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index d31da3220..8345aedb7 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -269,10 +269,10 @@ class TestMatrixPower(object): large[0,:] = t def test_large_power(self): - assert_equal(matrix_power(self.R90,2L**100+2**10+2**5+1),self.R90) + assert_equal(matrix_power(self.R90,2**100+2**10+2**5+1),self.R90) def test_large_power_trailing_zero(self): - assert_equal(matrix_power(self.R90,2L**100+2**10+2**5),identity(2)) + assert_equal(matrix_power(self.R90,2**100+2**10+2**5),identity(2)) def testip_zero(self): def tz(M): diff --git a/numpy/ma/core.py b/numpy/ma/core.py index d1c041566..23b60ee8c 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -32,7 +32,7 @@ import numpy.core.numerictypes as ntypes from numpy import ndarray, amax, amin, iscomplexobj, bool_ from numpy import array as narray from numpy.lib.function_base import angle -from numpy.compat import getargspec, formatargspec +from numpy.compat import getargspec, formatargspec, long from numpy import expand_dims as n_expand_dims if sys.version_info[0] >= 3: diff --git a/numpy/numarray/functions.py b/numpy/numarray/functions.py index 9b72a27e2..3f91046d2 100644 --- a/numpy/numarray/functions.py +++ b/numpy/numarray/functions.py @@ -31,14 +31,14 @@ import sys import math import operator +import numpy as np from numpy import dot as matrixmultiply, dot, vdot, ravel, concatenate, all,\ allclose, any, argsort, array_equal, array_equiv,\ array_str, array_repr, CLIP, RAISE, WRAP, clip, concatenate, \ diagonal, e, pi, inner as innerproduct, nonzero, \ outer as outerproduct, kron as kroneckerproduct, lexsort, putmask, rank, \ resize, searchsorted, shape, size, sort, swapaxes, trace, transpose -import numpy as np - +from numpy.compat import long from .numerictypes import typefrom if sys.version_info[0] >= 3: diff --git a/numpy/numarray/numerictypes.py b/numpy/numarray/numerictypes.py index caf40cf45..21685c34d 100644 --- a/numpy/numarray/numerictypes.py +++ b/numpy/numarray/numerictypes.py @@ -29,6 +29,8 @@ $Id: numerictypes.py,v 1.55 2005/12/01 16:22:03 jaytmiller Exp $ """ from __future__ import division, absolute_import, print_function +import numpy +from numpy.compat import long __all__ = ['NumericType','HasUInt64','typeDict','IsType', 'BooleanType', 'SignedType', 'UnsignedType', 'IntegralType', @@ -45,7 +47,6 @@ __all__ = ['NumericType','HasUInt64','typeDict','IsType', MAX_ALIGN = 8 MAX_INT_SIZE = 8 -import numpy LP64 = numpy.intp(0).itemsize == 8 HasUInt64 = 1 diff --git a/numpy/random/tests/test_regression.py b/numpy/random/tests/test_regression.py index 1f223f60d..d2bbdbfb7 100644 --- a/numpy/random/tests/test_regression.py +++ b/numpy/random/tests/test_regression.py @@ -3,6 +3,7 @@ from __future__ import division, absolute_import, print_function from numpy.testing import TestCase, run_module_suite, assert_,\ assert_array_equal from numpy import random +from numpy.compat import long import numpy as np @@ -42,7 +43,7 @@ class TestRegression(TestCase): np.random.seed(1234) a = np.random.permutation(12) np.random.seed(1234) - b = np.random.permutation(12L) + b = np.random.permutation(long(12)) assert_array_equal(a, b) def test_hypergeometric_range(self) : |