diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-04-21 22:52:15 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-04-24 19:29:58 -0600 |
commit | c92d924dd3dfa9eb97f65848e04ec9391709bc09 (patch) | |
tree | 665040ee28bf7b5f0885b8e7b21ac82bb472c8a5 | |
parent | d0d8d1c1deb28fb2b43c7180cd0e293608b6964e (diff) | |
download | numpy-c92d924dd3dfa9eb97f65848e04ec9391709bc09.tar.gz |
MAINT: Remove unneeded version checks.
Now that only Python versions 2.6-2.7 and 3.2-3.3 are supported
some version checks are no longer needed. This patch removes them
so as to clean up the code.
-rw-r--r-- | numpy/core/code_generators/genapi.py | 3 | ||||
-rw-r--r-- | numpy/core/defchararray.py | 588 | ||||
-rw-r--r-- | numpy/core/memmap.py | 12 | ||||
-rw-r--r-- | numpy/core/setup.py | 32 | ||||
-rw-r--r-- | numpy/core/tests/test_defchararray.py | 26 | ||||
-rw-r--r-- | numpy/core/tests/test_deprecations.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 678 | ||||
-rw-r--r-- | numpy/core/tests/test_print.py | 81 | ||||
-rw-r--r-- | numpy/core/tests/test_umath.py | 13 | ||||
-rw-r--r-- | numpy/lib/npyio.py | 3 | ||||
-rw-r--r-- | numpy/lib/utils.py | 15 | ||||
-rw-r--r-- | numpy/polynomial/polyutils.py | 10 |
13 files changed, 639 insertions, 826 deletions
diff --git a/numpy/core/code_generators/genapi.py b/numpy/core/code_generators/genapi.py index 85d7b04f6..62e4f9fc8 100644 --- a/numpy/core/code_generators/genapi.py +++ b/numpy/core/code_generators/genapi.py @@ -15,8 +15,7 @@ try: except ImportError: import md5 md5new = md5.new -if sys.version_info[:2] < (2, 6): - from sets import Set as set + import textwrap from os.path import join diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py index 874a295ef..2a8b31616 100644 --- a/numpy/core/defchararray.py +++ b/numpy/core/defchararray.py @@ -375,69 +375,42 @@ def capitalize(a): a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'capitalize') -if sys.version_info >= (2, 4): - def center(a, width, fillchar=' '): - """ - Return a copy of `a` with its elements centered in a string of - length `width`. - - Calls `str.center` element-wise. - - Parameters - ---------- - a : array_like of str or unicode - width : int - The length of the resulting strings - fillchar : str or unicode, optional - The padding character to use (default is space). +def center(a, width, fillchar=' '): + """ + Return a copy of `a` with its elements centered in a string of + length `width`. - Returns - ------- - out : ndarray - Output array of str or unicode, depending on input - types + Calls `str.center` element-wise. - See also - -------- - str.center + Parameters + ---------- + a : array_like of str or unicode - """ - a_arr = numpy.asarray(a) - width_arr = numpy.asarray(width) - size = long(numpy.max(width_arr.flat)) - if numpy.issubdtype(a_arr.dtype, numpy.string_): - fillchar = asbytes(fillchar) - return _vec_string( - a_arr, (a_arr.dtype.type, size), 'center', (width_arr, fillchar)) -else: - def center(a, width): - """ - Return an array with the elements of `a` centered in a string - of length width. + width : int + The length of the resulting strings + fillchar : str or unicode, optional + The padding character to use (default is space). - Calls `str.center` element-wise. + Returns + ------- + out : ndarray + Output array of str or unicode, depending on input + types - Parameters - ---------- - a : array_like of str or unicode - width : int - The length of the resulting strings + See also + -------- + str.center - Returns - ------- - out : ndarray, str or unicode - Output array of str or unicode, depending on input types + """ + a_arr = numpy.asarray(a) + width_arr = numpy.asarray(width) + size = long(numpy.max(width_arr.flat)) + if numpy.issubdtype(a_arr.dtype, numpy.string_): + fillchar = asbytes(fillchar) + return _vec_string( + a_arr, (a_arr.dtype.type, size), 'center', (width_arr, fillchar)) - See also - -------- - str.center - """ - a_arr = numpy.asarray(a) - width_arr = numpy.asarray(width) - size = long(numpy.max(width_arr.flat)) - return _vec_string( - a_arr, (a_arr.dtype.type, size), 'center', (width_arr,)) def count(a, sub, start=0, end=None): """ @@ -484,6 +457,7 @@ def count(a, sub, start=0, end=None): """ return _vec_string(a, integer, 'count', [sub, start] + _clean_args(end)) + def decode(a, encoding=None, errors=None): """ Calls `str.decode` element-wise. @@ -529,6 +503,7 @@ def decode(a, encoding=None, errors=None): return _to_string_or_unicode_array( _vec_string(a, object_, 'decode', _clean_args(encoding, errors))) + def encode(a, encoding=None, errors=None): """ Calls `str.encode` element-wise. @@ -563,6 +538,7 @@ def encode(a, encoding=None, errors=None): return _to_string_or_unicode_array( _vec_string(a, object_, 'encode', _clean_args(encoding, errors))) + def endswith(a, suffix, start=0, end=None): """ Returns a boolean array which is `True` where the string element @@ -606,6 +582,7 @@ def endswith(a, suffix, start=0, end=None): return _vec_string( a, bool_, 'endswith', [suffix, start] + _clean_args(end)) + def expandtabs(a, tabsize=8): """ Return a copy of each string element where all tab characters are @@ -640,6 +617,7 @@ def expandtabs(a, tabsize=8): return _to_string_or_unicode_array( _vec_string(a, object_, 'expandtabs', (tabsize,))) + def find(a, sub, start=0, end=None): """ For each element, return the lowest index in the string where @@ -674,10 +652,6 @@ def find(a, sub, start=0, end=None): return _vec_string( a, integer, 'find', [sub, start] + _clean_args(end)) -# if sys.version_info >= (2.6): -# def format(a, *args, **kwargs): -# # _vec_string doesn't support kwargs at present -# raise NotImplementedError def index(a, sub, start=0, end=None): """ @@ -901,68 +875,41 @@ def join(sep, seq): return _to_string_or_unicode_array( _vec_string(sep, object_, 'join', (seq,))) -if sys.version_info >= (2, 4): - def ljust(a, width, fillchar=' '): - """ - Return an array with the elements of `a` left-justified in a - string of length `width`. - - Calls `str.ljust` element-wise. - Parameters - ---------- - a : array_like of str or unicode - - width : int - The length of the resulting strings - fillchar : str or unicode, optional - The character to use for padding +def ljust(a, width, fillchar=' '): + """ + Return an array with the elements of `a` left-justified in a + string of length `width`. - Returns - ------- - out : ndarray - Output array of str or unicode, depending on input type + Calls `str.ljust` element-wise. - See also - -------- - str.ljust + Parameters + ---------- + a : array_like of str or unicode - """ - a_arr = numpy.asarray(a) - width_arr = numpy.asarray(width) - size = long(numpy.max(width_arr.flat)) - if numpy.issubdtype(a_arr.dtype, numpy.string_): - fillchar = asbytes(fillchar) - return _vec_string( - a_arr, (a_arr.dtype.type, size), 'ljust', (width_arr, fillchar)) -else: - def ljust(a, width): - """ - Return an array with the elements of `a` left-justified in a - string of length `width`. + width : int + The length of the resulting strings + fillchar : str or unicode, optional + The character to use for padding - Calls `str.ljust` element-wise. + Returns + ------- + out : ndarray + Output array of str or unicode, depending on input type - Parameters - ---------- - a : array_like of str or unicode - width : int - The length of the resulting strings + See also + -------- + str.ljust - Returns - ------- - out : ndarray - Output array of str or unicode, depending on input type + """ + a_arr = numpy.asarray(a) + width_arr = numpy.asarray(width) + size = long(numpy.max(width_arr.flat)) + if numpy.issubdtype(a_arr.dtype, numpy.string_): + fillchar = asbytes(fillchar) + return _vec_string( + a_arr, (a_arr.dtype.type, size), 'ljust', (width_arr, fillchar)) - See also - -------- - str.ljust - """ - a_arr = numpy.asarray(a) - width_arr = numpy.asarray(width) - size = long(numpy.max(width_arr.flat)) - return _vec_string( - a_arr, (a_arr.dtype.type, size), 'ljust', (width_arr,)) def lower(a): """ @@ -999,6 +946,7 @@ def lower(a): a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'lower') + def lstrip(a, chars=None): """ For each element in `a`, return a copy with the leading characters @@ -1055,40 +1003,41 @@ def lstrip(a, chars=None): a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'lstrip', (chars,)) -if sys.version_info >= (2, 5): - def partition(a, sep): - """ - Partition each element in `a` around `sep`. - Calls `str.partition` element-wise. +def partition(a, sep): + """ + Partition each element in `a` around `sep`. - For each element in `a`, split the element as the first - occurrence of `sep`, and return 3 strings containing the part - before the separator, the separator itself, and the part after - the separator. If the separator is not found, return 3 strings - containing the string itself, followed by two empty strings. + Calls `str.partition` element-wise. - Parameters - ---------- - a : array_like, {str, unicode} - Input array - sep : {str, unicode} - Separator to split each string element in `a`. + For each element in `a`, split the element as the first + occurrence of `sep`, and return 3 strings containing the part + before the separator, the separator itself, and the part after + the separator. If the separator is not found, return 3 strings + containing the string itself, followed by two empty strings. - Returns - ------- - out : ndarray, {str, unicode} - Output array of str or unicode, depending on input type. - The output array will have an extra dimension with 3 - elements per input element. + Parameters + ---------- + a : array_like, {str, unicode} + Input array + sep : {str, unicode} + Separator to split each string element in `a`. - See also - -------- - str.partition + Returns + ------- + out : ndarray, {str, unicode} + Output array of str or unicode, depending on input type. + The output array will have an extra dimension with 3 + elements per input element. + + See also + -------- + str.partition + + """ + return _to_string_or_unicode_array( + _vec_string(a, object_, 'partition', (sep,))) - """ - return _to_string_or_unicode_array( - _vec_string(a, object_, 'partition', (sep,))) def replace(a, old, new, count=None): """ @@ -1121,6 +1070,7 @@ def replace(a, old, new, count=None): _vec_string( a, object_, 'replace', [old, new] +_clean_args(count))) + def rfind(a, sub, start=0, end=None): """ For each element in `a`, return the highest index in the string @@ -1152,6 +1102,7 @@ def rfind(a, sub, start=0, end=None): return _vec_string( a, integer, 'rfind', [sub, start] + _clean_args(end)) + def rindex(a, sub, start=0, end=None): """ Like `rfind`, but raises `ValueError` when the substring `sub` is @@ -1180,140 +1131,113 @@ def rindex(a, sub, start=0, end=None): return _vec_string( a, integer, 'rindex', [sub, start] + _clean_args(end)) -if sys.version_info >= (2, 4): - def rjust(a, width, fillchar=' '): - """ - Return an array with the elements of `a` right-justified in a - string of length `width`. - Calls `str.rjust` element-wise. +def rjust(a, width, fillchar=' '): + """ + Return an array with the elements of `a` right-justified in a + string of length `width`. - Parameters - ---------- - a : array_like of str or unicode + Calls `str.rjust` element-wise. - width : int - The length of the resulting strings - fillchar : str or unicode, optional - The character to use for padding + Parameters + ---------- + a : array_like of str or unicode - Returns - ------- - out : ndarray - Output array of str or unicode, depending on input type + width : int + The length of the resulting strings + fillchar : str or unicode, optional + The character to use for padding - See also - -------- - str.rjust + Returns + ------- + out : ndarray + Output array of str or unicode, depending on input type - """ - a_arr = numpy.asarray(a) - width_arr = numpy.asarray(width) - size = long(numpy.max(width_arr.flat)) - if numpy.issubdtype(a_arr.dtype, numpy.string_): - fillchar = asbytes(fillchar) - return _vec_string( - a_arr, (a_arr.dtype.type, size), 'rjust', (width_arr, fillchar)) -else: - def rjust(a, width): - """ - Return an array with the elements of `a` right-justified in a - string of length `width`. + See also + -------- + str.rjust - Calls `str.rjust` element-wise. + """ + a_arr = numpy.asarray(a) + width_arr = numpy.asarray(width) + size = long(numpy.max(width_arr.flat)) + if numpy.issubdtype(a_arr.dtype, numpy.string_): + fillchar = asbytes(fillchar) + return _vec_string( + a_arr, (a_arr.dtype.type, size), 'rjust', (width_arr, fillchar)) - Parameters - ---------- - a : array_like of str or unicode - width : int - The length of the resulting strings - Returns - ------- - out : ndarray - Output array of str or unicode, depending on input type +def rpartition(a, sep): + """ + Partition (split) each element around the right-most separator. - See also - -------- - str.rjust - """ - a_arr = numpy.asarray(a) - width_arr = numpy.asarray(width) - size = long(numpy.max(width_arr.flat)) - return _vec_string( - a_arr, (a_arr.dtype.type, size), 'rjust', (width,)) + Calls `str.rpartition` element-wise. -if sys.version_info >= (2, 5): - def rpartition(a, sep): - """ - Partition (split) each element around the right-most separator. + For each element in `a`, split the element as the last + occurrence of `sep`, and return 3 strings containing the part + before the separator, the separator itself, and the part after + the separator. If the separator is not found, return 3 strings + containing the string itself, followed by two empty strings. - Calls `str.rpartition` element-wise. + Parameters + ---------- + a : array_like of str or unicode + Input array + sep : str or unicode + Right-most separator to split each element in array. - For each element in `a`, split the element as the last - occurrence of `sep`, and return 3 strings containing the part - before the separator, the separator itself, and the part after - the separator. If the separator is not found, return 3 strings - containing the string itself, followed by two empty strings. + Returns + ------- + out : ndarray + Output array of string or unicode, depending on input + type. The output array will have an extra dimension with + 3 elements per input element. - Parameters - ---------- - a : array_like of str or unicode - Input array - sep : str or unicode - Right-most separator to split each element in array. + See also + -------- + str.rpartition - Returns - ------- - out : ndarray - Output array of string or unicode, depending on input - type. The output array will have an extra dimension with - 3 elements per input element. + """ + return _to_string_or_unicode_array( + _vec_string(a, object_, 'rpartition', (sep,))) - See also - -------- - str.rpartition - """ - return _to_string_or_unicode_array( - _vec_string(a, object_, 'rpartition', (sep,))) +def rsplit(a, sep=None, maxsplit=None): + """ + For each element in `a`, return a list of the words in the + string, using `sep` as the delimiter string. -if sys.version_info >= (2, 4): - def rsplit(a, sep=None, maxsplit=None): - """ - For each element in `a`, return a list of the words in the - string, using `sep` as the delimiter string. + Calls `str.rsplit` element-wise. - Calls `str.rsplit` element-wise. + Except for splitting from the right, `rsplit` + behaves like `split`. - Except for splitting from the right, `rsplit` - behaves like `split`. + Parameters + ---------- + a : array_like of str or unicode - Parameters - ---------- - a : array_like of str or unicode + sep : str or unicode, optional + If `sep` is not specified or `None`, any whitespace string + is a separator. + maxsplit : int, optional + If `maxsplit` is given, at most `maxsplit` splits are done, + the rightmost ones. - sep : str or unicode, optional - If `sep` is not specified or `None`, any whitespace string - is a separator. - maxsplit : int, optional - If `maxsplit` is given, at most `maxsplit` splits are done, - the rightmost ones. + Returns + ------- + out : ndarray + Array of list objects - Returns - ------- - out : ndarray - Array of list objects + See also + -------- + str.rsplit, split - See also - -------- - str.rsplit, split + """ + # This will return an array of lists of different sizes, so we + # leave it as an object array + return _vec_string( + a, object_, 'rsplit', [sep] + _clean_args(maxsplit)) - """ - # This will return an array of lists of different sizes, so we - # leave it as an object array - return _vec_string( - a, object_, 'rsplit', [sep] + _clean_args(maxsplit)) def rstrip(a, chars=None): """ @@ -1358,6 +1282,7 @@ def rstrip(a, chars=None): a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'rstrip', (chars,)) + def split(a, sep=None, maxsplit=None): """ For each element in `a`, return a list of the words in the @@ -1391,6 +1316,7 @@ def split(a, sep=None, maxsplit=None): return _vec_string( a, object_, 'split', [sep] + _clean_args(maxsplit)) + def splitlines(a, keepends=None): """ For each element in `a`, return a list of the lines in the @@ -1419,6 +1345,7 @@ def splitlines(a, keepends=None): return _vec_string( a, object_, 'splitlines', _clean_args(keepends)) + def startswith(a, prefix, start=0, end=None): """ Returns a boolean array which is `True` where the string element @@ -1449,6 +1376,7 @@ def startswith(a, prefix, start=0, end=None): return _vec_string( a, bool_, 'startswith', [prefix, start] + _clean_args(end)) + def strip(a, chars=None): """ For each element in `a`, return a copy with the leading and @@ -1496,6 +1424,7 @@ def strip(a, chars=None): a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'strip', _clean_args(chars)) + def swapcase(a): """ Return element-wise a copy of the string with @@ -1532,6 +1461,7 @@ def swapcase(a): a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'swapcase') + def title(a): """ Return element-wise title cased version of string or unicode. @@ -1570,6 +1500,7 @@ def title(a): a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'title') + def translate(a, table, deletechars=None): """ For each element in `a`, return a copy of the string where all @@ -1605,6 +1536,7 @@ def translate(a, table, deletechars=None): return _vec_string( a_arr, a_arr.dtype, 'translate', [table] + _clean_args(deletechars)) + def upper(a): """ Return an array with the elements converted to uppercase. @@ -1640,6 +1572,7 @@ def upper(a): a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'upper') + def zfill(a, width): """ Return the numeric string left-filled with zeros @@ -1669,6 +1602,7 @@ def zfill(a, width): return _vec_string( a_arr, (a_arr.dtype.type, size), 'zfill', (width_arr,)) + def isnumeric(a): """ For each element, return True if there are only numeric @@ -1699,6 +1633,7 @@ def isnumeric(a): raise TypeError("isnumeric is only available for Unicode strings and arrays") return _vec_string(a, bool_, 'isnumeric') + def isdecimal(a): """ For each element, return True if there are only decimal @@ -2079,28 +2014,16 @@ class chararray(ndarray): """ return asarray(capitalize(self)) - if sys.version_info >= (2, 4): - def center(self, width, fillchar=' '): - """ - Return a copy of `self` with its elements centered in a - string of length `width`. - - See also - -------- - center - """ - return asarray(center(self, width, fillchar)) - else: - def center(self, width): - """ - Return a copy of `self` with its elements centered in a - string of length `width`. + def center(self, width, fillchar=' '): + """ + Return a copy of `self` with its elements centered in a + string of length `width`. - See also - -------- - center - """ - return asarray(center(self, width)) + See also + -------- + center + """ + return asarray(center(self, width, fillchar)) def count(self, sub, start=0, end=None): """ @@ -2285,29 +2208,17 @@ class chararray(ndarray): """ return join(self, seq) - if sys.version_info >= (2, 4): - def ljust(self, width, fillchar=' '): - """ - Return an array with the elements of `self` left-justified in a - string of length `width`. - - See also - -------- - char.ljust + def ljust(self, width, fillchar=' '): + """ + Return an array with the elements of `self` left-justified in a + string of length `width`. - """ - return asarray(ljust(self, width, fillchar)) - else: - def ljust(self, width): - """ - Return an array with the elements of `self` left-justified in a - string of length `width`. + See also + -------- + char.ljust - See also - -------- - ljust - """ - return asarray(ljust(self, width)) + """ + return asarray(ljust(self, width, fillchar)) def lower(self): """ @@ -2333,16 +2244,15 @@ class chararray(ndarray): """ return asarray(lstrip(self, chars)) - if sys.version_info >= (2, 5): - def partition(self, sep): - """ - Partition each element in `self` around `sep`. + def partition(self, sep): + """ + Partition each element in `self` around `sep`. - See also - -------- - partition - """ - return asarray(partition(self, sep)) + See also + -------- + partition + """ + return asarray(partition(self, sep)) def replace(self, old, new, count=None): """ @@ -2381,53 +2291,39 @@ class chararray(ndarray): """ return rindex(self, sub, start, end) - if sys.version_info >= (2, 4): - def rjust(self, width, fillchar=' '): - """ - Return an array with the elements of `self` - right-justified in a string of length `width`. + def rjust(self, width, fillchar=' '): + """ + Return an array with the elements of `self` + right-justified in a string of length `width`. + + See also + -------- + char.rjust - See also - -------- - char.rjust + """ + return asarray(rjust(self, width, fillchar)) - """ - return asarray(rjust(self, width, fillchar)) - else: - def rjust(self, width): - """ - Return an array with the elements of `self` - right-justified in a string of length `width`. - - See also - -------- - rjust - """ - return asarray(rjust(self, width)) - - if sys.version_info >= (2, 5): - def rpartition(self, sep): - """ - Partition each element in `self` around `sep`. - - See also - -------- - rpartition - """ - return asarray(rpartition(self, sep)) - - if sys.version_info >= (2, 4): - def rsplit(self, sep=None, maxsplit=None): - """ - For each element in `self`, return a list of the words in - the string, using `sep` as the delimiter string. - - See also - -------- - char.rsplit - - """ - return rsplit(self, sep, maxsplit) + def rpartition(self, sep): + """ + Partition each element in `self` around `sep`. + + See also + -------- + rpartition + """ + return asarray(rpartition(self, sep)) + + def rsplit(self, sep=None, maxsplit=None): + """ + For each element in `self`, return a list of the words in + the string, using `sep` as the delimiter string. + + See also + -------- + char.rsplit + + """ + return rsplit(self, sep, maxsplit) def rstrip(self, chars=None): """ diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index a4f049f2c..e6cbe7a71 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -248,14 +248,10 @@ class memmap(ndarray): else: acc = mmap.ACCESS_WRITE - if sys.version_info[:2] >= (2,6): - # The offset keyword in mmap.mmap needs Python >= 2.6 - start = offset - offset % mmap.ALLOCATIONGRANULARITY - bytes -= start - offset -= start - mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start) - else: - mm = mmap.mmap(fid.fileno(), bytes, access=acc) + start = offset - offset % mmap.ALLOCATIONGRANULARITY + bytes -= start + offset -= start + mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start) self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm, offset=offset, order=order) diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 4e4630eb0..0b2ecfe67 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -154,11 +154,10 @@ def check_math_capabilities(config, moredefs, mathlibs): # config.h in the public namespace, so we have a clash for the common # functions we test. We remove every function tested by python's # autoconf, hoping their own test are correct - if sys.version_info[:2] >= (2, 5): - for f in OPTIONAL_STDFUNCS_MAYBE: - if config.check_decl(fname2def(f), - headers=["Python.h", "math.h"]): - OPTIONAL_STDFUNCS.remove(f) + for f in OPTIONAL_STDFUNCS_MAYBE: + if config.check_decl(fname2def(f), + headers=["Python.h", "math.h"]): + OPTIONAL_STDFUNCS.remove(f) check_funcs(OPTIONAL_STDFUNCS) @@ -222,19 +221,16 @@ def check_ieee_macros(config): # functions we test. We remove every function tested by python's # autoconf, hoping their own test are correct _macros = ["isnan", "isinf", "signbit", "isfinite"] - if sys.version_info[:2] >= (2, 6): - for f in _macros: - py_symbol = fname2def("decl_%s" % f) - already_declared = config.check_decl(py_symbol, - headers=["Python.h", "math.h"]) - if already_declared: - if config.check_macro_true(py_symbol, - headers=["Python.h", "math.h"]): - pub.append('NPY_%s' % fname2def("decl_%s" % f)) - else: - macros.append(f) - else: - macros = _macros[:] + for f in _macros: + py_symbol = fname2def("decl_%s" % f) + already_declared = config.check_decl(py_symbol, + headers=["Python.h", "math.h"]) + if already_declared: + if config.check_macro_true(py_symbol, + headers=["Python.h", "math.h"]): + pub.append('NPY_%s' % fname2def("decl_%s" % f)) + else: + macros.append(f) # Normally, isnan and isinf are macro (C99), but some platforms only have # func, or both func and macro version. Check for macro only, and define # replacement ones if not found. diff --git a/numpy/core/tests/test_defchararray.py b/numpy/core/tests/test_defchararray.py index 37182722a..4656c842f 100644 --- a/numpy/core/tests/test_defchararray.py +++ b/numpy/core/tests/test_defchararray.py @@ -395,13 +395,12 @@ class TestMethods(TestCase): ['123 \t 345 \0 ', 'UPPER']]) def test_partition(self): - if sys.version_info >= (2, 5): - P = self.A.partition(asbytes_nested(['3', 'M'])) - assert_(issubclass(P.dtype.type, np.string_)) - assert_array_equal(P, asbytes_nested([ - [(' abc ', '', ''), ('', '', '')], - [('12', '3', '45'), ('', 'M', 'ixedCase')], - [('12', '3', ' \t 345 \0 '), ('UPPER', '', '')]])) + P = self.A.partition(asbytes_nested(['3', 'M'])) + assert_(issubclass(P.dtype.type, np.string_)) + assert_array_equal(P, asbytes_nested([ + [(' abc ', '', ''), ('', '', '')], + [('12', '3', '45'), ('', 'M', 'ixedCase')], + [('12', '3', ' \t 345 \0 '), ('UPPER', '', '')]])) def test_replace(self): R = self.A.replace(asbytes_nested(['3', 'a']), @@ -437,13 +436,12 @@ class TestMethods(TestCase): [' FOO', ' FOO']])) def test_rpartition(self): - if sys.version_info >= (2, 5): - P = self.A.rpartition(asbytes_nested(['3', 'M'])) - assert_(issubclass(P.dtype.type, np.string_)) - assert_array_equal(P, asbytes_nested([ - [('', '', ' abc '), ('', '', '')], - [('12', '3', '45'), ('', 'M', 'ixedCase')], - [('123 \t ', '3', '45 \0 '), ('', '', 'UPPER')]])) + P = self.A.rpartition(asbytes_nested(['3', 'M'])) + assert_(issubclass(P.dtype.type, np.string_)) + assert_array_equal(P, asbytes_nested([ + [('', '', ' abc '), ('', '', '')], + [('12', '3', '45'), ('', 'M', 'ixedCase')], + [('123 \t ', '3', '45 \0 '), ('', '', 'UPPER')]])) def test_rsplit(self): A = self.A.rsplit(asbytes('3')) diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index 5661deb02..9b77a1fc1 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -86,7 +86,6 @@ class TestFloatScalarIndexDeprecation(object): category=DeprecationWarning) - @dec.skipif(sys.version_info[:2] < (2, 5)) def test_deprecations(self): a = np.array([[[5]]]) @@ -159,7 +158,6 @@ class TestFloatSliceParameterDeprecation(object): category=DeprecationWarning) - @dec.skipif(sys.version_info[:2] < (2, 5)) def test_deprecations(self): a = np.array([[5]]) diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 21af2e82c..7493c20e2 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -440,7 +440,7 @@ class TestString(TestCase): assert_equal(repr(dt), "dtype([('a', '<M8[D]'), ('b', '<m8[us]')])") - @dec.skipif(sys.version_info[0] > 2) + @dec.skipif(sys.version_info[0] >= 3) def test_dtype_str_with_long_in_shape(self): # Pull request #376 dt = np.dtype('(1L,)i4') diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index e5986739e..e3520f123 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -2497,369 +2497,367 @@ class TestMinScalarType(object): def test_usigned_short(self): dt = np.min_scalar_type(2**16-1) wanted = np.dtype('uint16') - assert_equal(wanted, dt) + assert_equal(wanted, dt) def test_usigned_int(self): dt = np.min_scalar_type(2**32-1) wanted = np.dtype('uint32') - assert_equal(wanted, dt) + assert_equal(wanted, dt) def test_usigned_longlong(self): dt = np.min_scalar_type(2**63-1) wanted = np.dtype('uint64') - assert_equal(wanted, dt) + assert_equal(wanted, dt) def test_object(self): dt = np.min_scalar_type(2**64) wanted = np.dtype('O') assert_equal(wanted, dt) - -if sys.version_info >= (2, 6): - - if sys.version_info[:2] == (2, 6): - from numpy.core.multiarray import memorysimpleview as memoryview - - from numpy.core._internal import _dtype_from_pep3118 - - class TestPEP3118Dtype(object): - def _check(self, spec, wanted): - dt = np.dtype(wanted) - if isinstance(wanted, list) and isinstance(wanted[-1], tuple): - if wanted[-1][0] == '': - names = list(dt.names) - names[-1] = '' - dt.names = tuple(names) - assert_equal(_dtype_from_pep3118(spec), dt, - err_msg="spec %r != dtype %r" % (spec, wanted)) - - def test_native_padding(self): - align = np.dtype('i').alignment - for j in range(8): - if j == 0: - s = 'bi' - else: - s = 'b%dxi' % j - self._check('@'+s, {'f0': ('i1', 0), - 'f1': ('i', align*(1 + j//align))}) - self._check('='+s, {'f0': ('i1', 0), - 'f1': ('i', 1+j)}) - - def test_native_padding_2(self): - # Native padding should work also for structs and sub-arrays - self._check('x3T{xi}', {'f0': (({'f0': ('i', 4)}, (3,)), 4)}) - self._check('^x3T{xi}', {'f0': (({'f0': ('i', 1)}, (3,)), 1)}) - - def test_trailing_padding(self): - # Trailing padding should be included, *and*, the item size - # should match the alignment if in aligned mode - align = np.dtype('i').alignment - def VV(n): - return 'V%d' % (align*(1 + (n-1)//align)) - - self._check('ix', [('f0', 'i'), ('', VV(1))]) - self._check('ixx', [('f0', 'i'), ('', VV(2))]) - self._check('ixxx', [('f0', 'i'), ('', VV(3))]) - self._check('ixxxx', [('f0', 'i'), ('', VV(4))]) - self._check('i7x', [('f0', 'i'), ('', VV(7))]) - - self._check('^ix', [('f0', 'i'), ('', 'V1')]) - self._check('^ixx', [('f0', 'i'), ('', 'V2')]) - self._check('^ixxx', [('f0', 'i'), ('', 'V3')]) - self._check('^ixxxx', [('f0', 'i'), ('', 'V4')]) - self._check('^i7x', [('f0', 'i'), ('', 'V7')]) - - def test_native_padding_3(self): - dt = np.dtype( - [('a', 'b'), ('b', 'i'), - ('sub', np.dtype('b,i')), ('c', 'i')], - align=True) - self._check("T{b:a:xxxi:b:T{b:f0:=i:f1:}:sub:xxxi:c:}", dt) - - dt = np.dtype( - [('a', 'b'), ('b', 'i'), ('c', 'b'), ('d', 'b'), - ('e', 'b'), ('sub', np.dtype('b,i', align=True))]) - self._check("T{b:a:=i:b:b:c:b:d:b:e:T{b:f0:xxxi:f1:}:sub:}", dt) - - def test_padding_with_array_inside_struct(self): - dt = np.dtype( - [('a', 'b'), ('b', 'i'), ('c', 'b', (3,)), - ('d', 'i')], - align=True) - self._check("T{b:a:xxxi:b:3b:c:xi:d:}", dt) - - def test_byteorder_inside_struct(self): - # The byte order after @T{=i} should be '=', not '@'. - # Check this by noting the absence of native alignment. - self._check('@T{^i}xi', {'f0': ({'f0': ('i', 0)}, 0), - 'f1': ('i', 5)}) - - def test_intra_padding(self): - # Natively aligned sub-arrays may require some internal padding - align = np.dtype('i').alignment - def VV(n): - return 'V%d' % (align*(1 + (n-1)//align)) - - self._check('(3)T{ix}', ({'f0': ('i', 0), '': (VV(1), 4)}, (3,))) - - class TestNewBufferProtocol(object): - def _check_roundtrip(self, obj): - obj = np.asarray(obj) - x = memoryview(obj) - y = np.asarray(x) - y2 = np.array(x) - assert_(not y.flags.owndata) - assert_(y2.flags.owndata) - assert_equal(y.dtype, obj.dtype) - assert_array_equal(obj, y) - assert_equal(y2.dtype, obj.dtype) - assert_array_equal(obj, y2) - - def test_roundtrip(self): - x = np.array([1,2,3,4,5], dtype='i4') - self._check_roundtrip(x) - x = np.array([[1,2],[3,4]], dtype=np.float64) - self._check_roundtrip(x) +if sys.version_info[:2] == (2, 6): + from numpy.core.multiarray import memorysimpleview as memoryview - x = np.zeros((3,3,3), dtype=np.float32)[:,0,:] - self._check_roundtrip(x) +from numpy.core._internal import _dtype_from_pep3118 - dt = [('a', 'b'), - ('b', 'h'), - ('c', 'i'), - ('d', 'l'), - ('dx', 'q'), - ('e', 'B'), - ('f', 'H'), - ('g', 'I'), - ('h', 'L'), - ('hx', 'Q'), - ('i', np.single), - ('j', np.double), - ('k', np.longdouble), - ('ix', np.csingle), - ('jx', np.cdouble), - ('kx', np.clongdouble), - ('l', 'S4'), - ('m', 'U4'), - ('n', 'V3'), - ('o', '?'), - ('p', np.half), - ] - x = np.array( - [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - asbytes('aaaa'), 'bbbb', asbytes('xxx'), True, 1.0)], - dtype=dt) - self._check_roundtrip(x) +class TestPEP3118Dtype(object): + def _check(self, spec, wanted): + dt = np.dtype(wanted) + if isinstance(wanted, list) and isinstance(wanted[-1], tuple): + if wanted[-1][0] == '': + names = list(dt.names) + names[-1] = '' + dt.names = tuple(names) + assert_equal(_dtype_from_pep3118(spec), dt, + err_msg="spec %r != dtype %r" % (spec, wanted)) - x = np.array(([[1,2],[3,4]],), dtype=[('a', (int, (2,2)))]) - self._check_roundtrip(x) + def test_native_padding(self): + align = np.dtype('i').alignment + for j in range(8): + if j == 0: + s = 'bi' + else: + s = 'b%dxi' % j + self._check('@'+s, {'f0': ('i1', 0), + 'f1': ('i', align*(1 + j//align))}) + self._check('='+s, {'f0': ('i1', 0), + 'f1': ('i', 1+j)}) + + def test_native_padding_2(self): + # Native padding should work also for structs and sub-arrays + self._check('x3T{xi}', {'f0': (({'f0': ('i', 4)}, (3,)), 4)}) + self._check('^x3T{xi}', {'f0': (({'f0': ('i', 1)}, (3,)), 1)}) + + def test_trailing_padding(self): + # Trailing padding should be included, *and*, the item size + # should match the alignment if in aligned mode + align = np.dtype('i').alignment + def VV(n): + return 'V%d' % (align*(1 + (n-1)//align)) + + self._check('ix', [('f0', 'i'), ('', VV(1))]) + self._check('ixx', [('f0', 'i'), ('', VV(2))]) + self._check('ixxx', [('f0', 'i'), ('', VV(3))]) + self._check('ixxxx', [('f0', 'i'), ('', VV(4))]) + self._check('i7x', [('f0', 'i'), ('', VV(7))]) + + self._check('^ix', [('f0', 'i'), ('', 'V1')]) + self._check('^ixx', [('f0', 'i'), ('', 'V2')]) + self._check('^ixxx', [('f0', 'i'), ('', 'V3')]) + self._check('^ixxxx', [('f0', 'i'), ('', 'V4')]) + self._check('^i7x', [('f0', 'i'), ('', 'V7')]) + + def test_native_padding_3(self): + dt = np.dtype( + [('a', 'b'), ('b', 'i'), + ('sub', np.dtype('b,i')), ('c', 'i')], + align=True) + self._check("T{b:a:xxxi:b:T{b:f0:=i:f1:}:sub:xxxi:c:}", dt) + + dt = np.dtype( + [('a', 'b'), ('b', 'i'), ('c', 'b'), ('d', 'b'), + ('e', 'b'), ('sub', np.dtype('b,i', align=True))]) + self._check("T{b:a:=i:b:b:c:b:d:b:e:T{b:f0:xxxi:f1:}:sub:}", dt) + + def test_padding_with_array_inside_struct(self): + dt = np.dtype( + [('a', 'b'), ('b', 'i'), ('c', 'b', (3,)), + ('d', 'i')], + align=True) + self._check("T{b:a:xxxi:b:3b:c:xi:d:}", dt) + + def test_byteorder_inside_struct(self): + # The byte order after @T{=i} should be '=', not '@'. + # Check this by noting the absence of native alignment. + self._check('@T{^i}xi', {'f0': ({'f0': ('i', 0)}, 0), + 'f1': ('i', 5)}) + + def test_intra_padding(self): + # Natively aligned sub-arrays may require some internal padding + align = np.dtype('i').alignment + def VV(n): + return 'V%d' % (align*(1 + (n-1)//align)) + + self._check('(3)T{ix}', ({'f0': ('i', 0), '': (VV(1), 4)}, (3,))) + +class TestNewBufferProtocol(object): + def _check_roundtrip(self, obj): + obj = np.asarray(obj) + x = memoryview(obj) + y = np.asarray(x) + y2 = np.array(x) + assert_(not y.flags.owndata) + assert_(y2.flags.owndata) + assert_equal(y.dtype, obj.dtype) + assert_array_equal(obj, y) + assert_equal(y2.dtype, obj.dtype) + assert_array_equal(obj, y2) - x = np.array([1,2,3], dtype='>i2') + def test_roundtrip(self): + x = np.array([1,2,3,4,5], dtype='i4') + self._check_roundtrip(x) + + x = np.array([[1,2],[3,4]], dtype=np.float64) + self._check_roundtrip(x) + + x = np.zeros((3,3,3), dtype=np.float32)[:,0,:] + self._check_roundtrip(x) + + dt = [('a', 'b'), + ('b', 'h'), + ('c', 'i'), + ('d', 'l'), + ('dx', 'q'), + ('e', 'B'), + ('f', 'H'), + ('g', 'I'), + ('h', 'L'), + ('hx', 'Q'), + ('i', np.single), + ('j', np.double), + ('k', np.longdouble), + ('ix', np.csingle), + ('jx', np.cdouble), + ('kx', np.clongdouble), + ('l', 'S4'), + ('m', 'U4'), + ('n', 'V3'), + ('o', '?'), + ('p', np.half), + ] + x = np.array( + [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + asbytes('aaaa'), 'bbbb', asbytes('xxx'), True, 1.0)], + dtype=dt) + self._check_roundtrip(x) + + x = np.array(([[1,2],[3,4]],), dtype=[('a', (int, (2,2)))]) + self._check_roundtrip(x) + + x = np.array([1,2,3], dtype='>i2') + self._check_roundtrip(x) + + x = np.array([1,2,3], dtype='<i2') + self._check_roundtrip(x) + + x = np.array([1,2,3], dtype='>i4') + self._check_roundtrip(x) + + x = np.array([1,2,3], dtype='<i4') + self._check_roundtrip(x) + + # Native-only data types can be passed through the buffer interface + # only in native byte order + if sys.byteorder == 'little': + x = np.array([1,2,3], dtype='>q') + assert_raises(ValueError, self._check_roundtrip, x) + x = np.array([1,2,3], dtype='<q') self._check_roundtrip(x) - - x = np.array([1,2,3], dtype='<i2') + else: + x = np.array([1,2,3], dtype='>q') self._check_roundtrip(x) + x = np.array([1,2,3], dtype='<q') + assert_raises(ValueError, self._check_roundtrip, x) + + def test_roundtrip_half(self): + half_list = [ + 1.0, + -2.0, + 6.5504 * 10**4, # (max half precision) + 2**-14, # ~= 6.10352 * 10**-5 (minimum positive normal) + 2**-24, # ~= 5.96046 * 10**-8 (minimum strictly positive subnormal) + 0.0, + -0.0, + float('+inf'), + float('-inf'), + 0.333251953125, # ~= 1/3 + ] - x = np.array([1,2,3], dtype='>i4') - self._check_roundtrip(x) + x = np.array(half_list, dtype='>e') + self._check_roundtrip(x) + x = np.array(half_list, dtype='<e') + self._check_roundtrip(x) + + def test_export_simple_1d(self): + x = np.array([1,2,3,4,5], dtype='i') + y = memoryview(x) + assert_equal(y.format, 'i') + assert_equal(y.shape, (5,)) + assert_equal(y.ndim, 1) + assert_equal(y.strides, (4,)) + assert_equal(y.suboffsets, EMPTY) + assert_equal(y.itemsize, 4) + + def test_export_simple_nd(self): + x = np.array([[1,2],[3,4]], dtype=np.float64) + y = memoryview(x) + assert_equal(y.format, 'd') + assert_equal(y.shape, (2, 2)) + assert_equal(y.ndim, 2) + assert_equal(y.strides, (16, 8)) + assert_equal(y.suboffsets, EMPTY) + assert_equal(y.itemsize, 8) + + def test_export_discontiguous(self): + x = np.zeros((3,3,3), dtype=np.float32)[:,0,:] + y = memoryview(x) + assert_equal(y.format, 'f') + assert_equal(y.shape, (3, 3)) + assert_equal(y.ndim, 2) + assert_equal(y.strides, (36, 4)) + assert_equal(y.suboffsets, EMPTY) + assert_equal(y.itemsize, 4) + + def test_export_record(self): + dt = [('a', 'b'), + ('b', 'h'), + ('c', 'i'), + ('d', 'l'), + ('dx', 'q'), + ('e', 'B'), + ('f', 'H'), + ('g', 'I'), + ('h', 'L'), + ('hx', 'Q'), + ('i', np.single), + ('j', np.double), + ('k', np.longdouble), + ('ix', np.csingle), + ('jx', np.cdouble), + ('kx', np.clongdouble), + ('l', 'S4'), + ('m', 'U4'), + ('n', 'V3'), + ('o', '?'), + ('p', np.half), + ] + x = np.array( + [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + asbytes('aaaa'), 'bbbb', asbytes(' '), True, 1.0)], + dtype=dt) + y = memoryview(x) + assert_equal(y.shape, (1,)) + assert_equal(y.ndim, 1) + assert_equal(y.suboffsets, EMPTY) + + sz = sum([dtype(b).itemsize for a, b in dt]) + if dtype('l').itemsize == 4: + assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:^q:dx:B:e:@H:f:=I:g:L:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}') + else: + assert_equal(y.format, 'T{b:a:=h:b:i:c:q:d:^q:dx:B:e:@H:f:=I:g:Q:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}') + # Cannot test if NPY_RELAXED_STRIDES_CHECKING changes the strides + if not (np.ones(1).strides[0] == np.iinfo(np.intp).max): + assert_equal(y.strides, (sz,)) + assert_equal(y.itemsize, sz) + + def test_export_subarray(self): + x = np.array(([[1,2],[3,4]],), dtype=[('a', ('i', (2,2)))]) + y = memoryview(x) + assert_equal(y.format, 'T{(2,2)i:a:}') + assert_equal(y.shape, EMPTY) + assert_equal(y.ndim, 0) + assert_equal(y.strides, EMPTY) + assert_equal(y.suboffsets, EMPTY) + assert_equal(y.itemsize, 16) + + def test_export_endian(self): + x = np.array([1,2,3], dtype='>i') + y = memoryview(x) + if sys.byteorder == 'little': + assert_equal(y.format, '>i') + else: + assert_equal(y.format, 'i') - x = np.array([1,2,3], dtype='<i4') - self._check_roundtrip(x) + x = np.array([1,2,3], dtype='<i') + y = memoryview(x) + if sys.byteorder == 'little': + assert_equal(y.format, 'i') + else: + assert_equal(y.format, '<i') - # Native-only data types can be passed through the buffer interface - # only in native byte order - if sys.byteorder == 'little': - x = np.array([1,2,3], dtype='>q') - assert_raises(ValueError, self._check_roundtrip, x) - x = np.array([1,2,3], dtype='<q') - self._check_roundtrip(x) - else: - x = np.array([1,2,3], dtype='>q') - self._check_roundtrip(x) - x = np.array([1,2,3], dtype='<q') - assert_raises(ValueError, self._check_roundtrip, x) - - def test_roundtrip_half(self): - half_list = [ - 1.0, - -2.0, - 6.5504 * 10**4, # (max half precision) - 2**-14, # ~= 6.10352 * 10**-5 (minimum positive normal) - 2**-24, # ~= 5.96046 * 10**-8 (minimum strictly positive subnormal) - 0.0, - -0.0, - float('+inf'), - float('-inf'), - 0.333251953125, # ~= 1/3 - ] - - x = np.array(half_list, dtype='>e') + def test_padding(self): + for j in range(8): + x = np.array([(1,),(2,)], dtype={'f0': (int, j)}) self._check_roundtrip(x) - x = np.array(half_list, dtype='<e') - self._check_roundtrip(x) - - def test_export_simple_1d(self): - x = np.array([1,2,3,4,5], dtype='i') - y = memoryview(x) - assert_equal(y.format, 'i') - assert_equal(y.shape, (5,)) - assert_equal(y.ndim, 1) - assert_equal(y.strides, (4,)) - assert_equal(y.suboffsets, EMPTY) - assert_equal(y.itemsize, 4) - - def test_export_simple_nd(self): - x = np.array([[1,2],[3,4]], dtype=np.float64) - y = memoryview(x) - assert_equal(y.format, 'd') - assert_equal(y.shape, (2, 2)) - assert_equal(y.ndim, 2) - assert_equal(y.strides, (16, 8)) - assert_equal(y.suboffsets, EMPTY) - assert_equal(y.itemsize, 8) - - def test_export_discontiguous(self): - x = np.zeros((3,3,3), dtype=np.float32)[:,0,:] - y = memoryview(x) - assert_equal(y.format, 'f') - assert_equal(y.shape, (3, 3)) - assert_equal(y.ndim, 2) - assert_equal(y.strides, (36, 4)) - assert_equal(y.suboffsets, EMPTY) - assert_equal(y.itemsize, 4) - - def test_export_record(self): - dt = [('a', 'b'), - ('b', 'h'), - ('c', 'i'), - ('d', 'l'), - ('dx', 'q'), - ('e', 'B'), - ('f', 'H'), - ('g', 'I'), - ('h', 'L'), - ('hx', 'Q'), - ('i', np.single), - ('j', np.double), - ('k', np.longdouble), - ('ix', np.csingle), - ('jx', np.cdouble), - ('kx', np.clongdouble), - ('l', 'S4'), - ('m', 'U4'), - ('n', 'V3'), - ('o', '?'), - ('p', np.half), - ] - x = np.array( - [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - asbytes('aaaa'), 'bbbb', asbytes(' '), True, 1.0)], - dtype=dt) - y = memoryview(x) - assert_equal(y.shape, (1,)) - assert_equal(y.ndim, 1) - assert_equal(y.suboffsets, EMPTY) - - sz = sum([dtype(b).itemsize for a, b in dt]) - if dtype('l').itemsize == 4: - assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:^q:dx:B:e:@H:f:=I:g:L:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}') - else: - assert_equal(y.format, 'T{b:a:=h:b:i:c:q:d:^q:dx:B:e:@H:f:=I:g:Q:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}') - # Cannot test if NPY_RELAXED_STRIDES_CHECKING changes the strides - if not (np.ones(1).strides[0] == np.iinfo(np.intp).max): - assert_equal(y.strides, (sz,)) - assert_equal(y.itemsize, sz) - - def test_export_subarray(self): - x = np.array(([[1,2],[3,4]],), dtype=[('a', ('i', (2,2)))]) - y = memoryview(x) - assert_equal(y.format, 'T{(2,2)i:a:}') - assert_equal(y.shape, EMPTY) - assert_equal(y.ndim, 0) - assert_equal(y.strides, EMPTY) - assert_equal(y.suboffsets, EMPTY) - assert_equal(y.itemsize, 16) - - def test_export_endian(self): - x = np.array([1,2,3], dtype='>i') - y = memoryview(x) - if sys.byteorder == 'little': - assert_equal(y.format, '>i') - else: - assert_equal(y.format, 'i') - x = np.array([1,2,3], dtype='<i') - y = memoryview(x) - if sys.byteorder == 'little': - assert_equal(y.format, 'i') - else: - assert_equal(y.format, '<i') - - def test_padding(self): - for j in range(8): - x = np.array([(1,),(2,)], dtype={'f0': (int, j)}) - self._check_roundtrip(x) - - def test_reference_leak(self): - count_1 = sys.getrefcount(np.core._internal) - a = np.zeros(4) - b = memoryview(a) - c = np.asarray(b) - count_2 = sys.getrefcount(np.core._internal) - assert_equal(count_1, count_2) - - def test_padded_struct_array(self): - dt1 = np.dtype( - [('a', 'b'), ('b', 'i'), ('sub', np.dtype('b,i')), ('c', 'i')], - align=True) - x1 = np.arange(dt1.itemsize, dtype=np.int8).view(dt1) - self._check_roundtrip(x1) - - dt2 = np.dtype( - [('a', 'b'), ('b', 'i'), ('c', 'b', (3,)), ('d', 'i')], - align=True) - x2 = np.arange(dt2.itemsize, dtype=np.int8).view(dt2) - self._check_roundtrip(x2) - - dt3 = np.dtype( - [('a', 'b'), ('b', 'i'), ('c', 'b'), ('d', 'b'), - ('e', 'b'), ('sub', np.dtype('b,i', align=True))]) - x3 = np.arange(dt3.itemsize, dtype=np.int8).view(dt3) - self._check_roundtrip(x3) - - - class TestArrayAttributeDeletion(object): - - def test_multiarray_writable_attributes_deletion(self): - """ticket #2046, should not seqfault, raise AttributeError""" - a = np.ones(2) - attr = ['shape', 'strides', 'data', 'dtype', 'real', 'imag', 'flat'] - for s in attr: - assert_raises(AttributeError, delattr, a, s) - - - def test_multiarray_not_writable_attributes_deletion(self): - a = np.ones(2) - attr = ["ndim", "flags", "itemsize", "size", "nbytes", "base", - "ctypes", "T", "__array_interface__", "__array_struct__", - "__array_priority__", "__array_finalize__"] - for s in attr: - assert_raises(AttributeError, delattr, a, s) - - - def test_multiarray_flags_writable_attribute_deletion(self): - a = np.ones(2).flags - attr = ['updateifcopy', 'aligned', 'writeable'] - for s in attr: - assert_raises(AttributeError, delattr, a, s) - - - def test_multiarray_flags_not_writable_attribute_deletion(self): - a = np.ones(2).flags - attr = ["contiguous", "c_contiguous", "f_contiguous", "fortran", - "owndata", "fnc", "forc", "behaved", "carray", "farray", - "num"] - for s in attr: - assert_raises(AttributeError, delattr, a, s) + def test_reference_leak(self): + count_1 = sys.getrefcount(np.core._internal) + a = np.zeros(4) + b = memoryview(a) + c = np.asarray(b) + count_2 = sys.getrefcount(np.core._internal) + assert_equal(count_1, count_2) + + def test_padded_struct_array(self): + dt1 = np.dtype( + [('a', 'b'), ('b', 'i'), ('sub', np.dtype('b,i')), ('c', 'i')], + align=True) + x1 = np.arange(dt1.itemsize, dtype=np.int8).view(dt1) + self._check_roundtrip(x1) + + dt2 = np.dtype( + [('a', 'b'), ('b', 'i'), ('c', 'b', (3,)), ('d', 'i')], + align=True) + x2 = np.arange(dt2.itemsize, dtype=np.int8).view(dt2) + self._check_roundtrip(x2) + + dt3 = np.dtype( + [('a', 'b'), ('b', 'i'), ('c', 'b'), ('d', 'b'), + ('e', 'b'), ('sub', np.dtype('b,i', align=True))]) + x3 = np.arange(dt3.itemsize, dtype=np.int8).view(dt3) + self._check_roundtrip(x3) + + +class TestArrayAttributeDeletion(object): + + def test_multiarray_writable_attributes_deletion(self): + """ticket #2046, should not seqfault, raise AttributeError""" + a = np.ones(2) + attr = ['shape', 'strides', 'data', 'dtype', 'real', 'imag', 'flat'] + for s in attr: + assert_raises(AttributeError, delattr, a, s) + + + def test_multiarray_not_writable_attributes_deletion(self): + a = np.ones(2) + attr = ["ndim", "flags", "itemsize", "size", "nbytes", "base", + "ctypes", "T", "__array_interface__", "__array_struct__", + "__array_priority__", "__array_finalize__"] + for s in attr: + assert_raises(AttributeError, delattr, a, s) + + + def test_multiarray_flags_writable_attribute_deletion(self): + a = np.ones(2).flags + attr = ['updateifcopy', 'aligned', 'writeable'] + for s in attr: + assert_raises(AttributeError, delattr, a, s) + + + def test_multiarray_flags_not_writable_attribute_deletion(self): + a = np.ones(2).flags + attr = ["contiguous", "c_contiguous", "f_contiguous", "fortran", + "owndata", "fnc", "forc", "behaved", "carray", "farray", + "num"] + for s in attr: + assert_raises(AttributeError, delattr, a, s) def test_array_interface(): # Test scalar coercion within the array interface diff --git a/numpy/core/tests/test_print.py b/numpy/core/tests/test_print.py index c31771ad7..342ca27c6 100644 --- a/numpy/core/tests/test_print.py +++ b/numpy/core/tests/test_print.py @@ -24,11 +24,7 @@ def check_float_type(tp): assert_equal(str(tp(1e10)), str(float('1e10')), err_msg='Failed str formatting for type %s' % tp) else: - if sys.platform == 'win32' and sys.version_info[0] <= 2 and \ - sys.version_info[1] <= 5: - ref = '1e+010' - else: - ref = '1e+10' + ref = '1e+10' assert_equal(str(tp(1e10)), ref, err_msg='Failed str formatting for type %s' % tp) @@ -72,11 +68,7 @@ def check_complex_type(tp): assert_equal(str(tp(1e10)), str(complex(1e10)), err_msg='Failed str formatting for type %s' % tp) else: - if sys.platform == 'win32' and sys.version_info[0] <= 2 and \ - sys.version_info[1] <= 5: - ref = '(1e+010+0j)' - else: - ref = '(1e+10+0j)' + ref = '(1e+10+0j)' assert_equal(str(tp(1e10)), ref, err_msg='Failed str formatting for type %s' % tp) @@ -93,44 +85,24 @@ def test_complex_types(): def test_complex_inf_nan(): """Check inf/nan formatting of complex types.""" - if sys.version_info[:2] >= (2, 6): - TESTS = { - complex(np.inf, 0): "(inf+0j)", - complex(0, np.inf): "inf*j", - complex(-np.inf, 0): "(-inf+0j)", - complex(0, -np.inf): "-inf*j", - complex(np.inf, 1): "(inf+1j)", - complex(1, np.inf): "(1+inf*j)", - complex(-np.inf, 1): "(-inf+1j)", - complex(1, -np.inf): "(1-inf*j)", - complex(np.nan, 0): "(nan+0j)", - complex(0, np.nan): "nan*j", - complex(-np.nan, 0): "(nan+0j)", - complex(0, -np.nan): "nan*j", - complex(np.nan, 1): "(nan+1j)", - complex(1, np.nan): "(1+nan*j)", - complex(-np.nan, 1): "(nan+1j)", - complex(1, -np.nan): "(1+nan*j)", - } - else: - TESTS = { - complex(np.inf, 0): "(inf+0j)", - complex(0, np.inf): "infj", - complex(-np.inf, 0): "(-inf+0j)", - complex(0, -np.inf): "-infj", - complex(np.inf, 1): "(inf+1j)", - complex(1, np.inf): "(1+infj)", - complex(-np.inf, 1): "(-inf+1j)", - complex(1, -np.inf): "(1-infj)", - complex(np.nan, 0): "(nan+0j)", - complex(0, np.nan): "nanj", - complex(-np.nan, 0): "(nan+0j)", - complex(0, -np.nan): "nanj", - complex(np.nan, 1): "(nan+1j)", - complex(1, np.nan): "(1+nanj)", - complex(-np.nan, 1): "(nan+1j)", - complex(1, -np.nan): "(1+nanj)", - } + TESTS = { + complex(np.inf, 0): "(inf+0j)", + complex(0, np.inf): "inf*j", + complex(-np.inf, 0): "(-inf+0j)", + complex(0, -np.inf): "-inf*j", + complex(np.inf, 1): "(inf+1j)", + complex(1, np.inf): "(1+inf*j)", + complex(-np.inf, 1): "(-inf+1j)", + complex(1, -np.inf): "(1-inf*j)", + complex(np.nan, 0): "(nan+0j)", + complex(0, np.nan): "nan*j", + complex(-np.nan, 0): "(nan+0j)", + complex(0, -np.nan): "nan*j", + complex(np.nan, 1): "(nan+1j)", + complex(1, np.nan): "(1+nan*j)", + complex(-np.nan, 1): "(nan+1j)", + complex(1, -np.nan): "(1+nan*j)", + } for tp in [np.complex64, np.cdouble, np.clongdouble]: for c, s in TESTS.items(): yield _check_complex_inf_nan, c, s, tp @@ -167,11 +139,7 @@ def check_float_type_print(tp): if tp(1e10).itemsize > 4: _test_redirected_print(float(1e10), tp) else: - if sys.platform == 'win32' and sys.version_info[0] <= 2 and \ - sys.version_info[1] <= 5: - ref = '1e+010' - else: - ref = '1e+10' + ref = '1e+10' _test_redirected_print(float(1e10), tp, ref) def check_complex_type_print(tp): @@ -183,11 +151,7 @@ def check_complex_type_print(tp): if tp(1e10).itemsize > 8: _test_redirected_print(complex(1e10), tp) else: - if sys.platform == 'win32' and sys.version_info[0] <= 2 and \ - sys.version_info[1] <= 5: - ref = '(1e+010+0j)' - else: - ref = '(1e+10+0j)' + ref = '(1e+10+0j)' _test_redirected_print(complex(1e10), tp, ref) _test_redirected_print(complex(np.inf, 1), tp, '(inf+1j)') @@ -204,7 +168,6 @@ def test_complex_type_print(): for t in [np.complex64, np.cdouble, np.clongdouble] : yield check_complex_type_print, t -@dec.skipif(sys.version_info[:2] < (2, 6)) def test_scalar_format(): """Test the str.format method with NumPy scalar types""" tests = [('{0}', True, np.bool_), diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 173707351..ea92ce7de 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -447,9 +447,6 @@ class TestLdexp(TestCase): self._check_ldexp('i') self._check_ldexp('l') - @dec.knownfailureif(sys.platform == 'win32' and sys.version_info < (2, 6), - "python.org < 2.6 binaries have broken ldexp in the " - "C runtime") def test_ldexp_overflow(self): # silence warning emitted on overflow err = np.seterr(over="ignore") @@ -916,12 +913,6 @@ class TestComplexFunctions(object): def test_against_cmath(self): import cmath, sys - # cmath.asinh is broken in some versions of Python, see - # http://bugs.python.org/issue1381 - broken_cmath_asinh = False - if sys.version_info < (2,6): - broken_cmath_asinh = True - points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} @@ -936,10 +927,6 @@ class TestComplexFunctions(object): for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) - - if cname == 'asinh' and broken_cmath_asinh: - continue - assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s"%(fname,p,a,b)) def check_loss_of_precision(self, dtype): diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index b084d6af7..c13c7e94a 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -129,8 +129,7 @@ class BagObj(object): def zipfile_factory(*args, **kwargs): import zipfile - if sys.version_info >= (2, 5): - kwargs['allowZip64'] = True + kwargs['allowZip64'] = True return zipfile.ZipFile(*args, **kwargs) class NpzFile(object): diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 75ba5bca6..2519cd4d4 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -84,17 +84,10 @@ def get_numarray_include(type=None): return include_dirs + [get_include()] -if sys.version_info < (2, 4): - # Can't set __name__ in 2.3 - import new - def _set_function_name(func, name): - func = new.function(func.__code__, func.__globals__, - name, func.__defaults__, func.__closure__) - return func -else: - def _set_function_name(func, name): - func.__name__ = name - return func +def _set_function_name(func, name): + func.__name__ = name + return func + class _Deprecate(object): """ diff --git a/numpy/polynomial/polyutils.py b/numpy/polynomial/polyutils.py index c8121e633..63743bb40 100644 --- a/numpy/polynomial/polyutils.py +++ b/numpy/polynomial/polyutils.py @@ -70,16 +70,6 @@ class PolyBase(object) : pass # -# We need the any function for python < 2.5 -# -if sys.version_info[:2] < (2,5) : - def any(iterable) : - for element in iterable: - if element : - return True - return False - -# # Helper functions to convert inputs to 1-D arrays # def trimseq(seq) : |