From 26dafcc295484702361015373a8174564335a031 Mon Sep 17 00:00:00 2001 From: "Eric O. LEBIGOT (EOL)" Date: Sat, 23 Nov 2019 22:10:27 +0100 Subject: [PATCH] Bumped version for upload to PyPI. --- setup.py | 2 +- uncertainties/__init__.py | 2 +- uncertainties/core.py | 82 ++++++++++++++-------------- uncertainties/lib1to2/test_1to2.py | 14 ++--- uncertainties/test_umath.py | 16 +++--- uncertainties/test_uncertainties.py | 70 ++++++++++++------------ uncertainties/umath_core.py | 8 +-- uncertainties/unumpy/core.py | 14 ++--- uncertainties/unumpy/test_ulinalg.py | 2 +- uncertainties/unumpy/test_unumpy.py | 2 +- 10 files changed, 106 insertions(+), 106 deletions(-) diff --git a/setup.py b/setup.py index f58e9d70..00446475 100755 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ # Common options for distutils/setuptools's setup(): setup_options = dict( name='uncertainties', - version='3.1.2', + version='3.1.3', author='Eric O. LEBIGOT (EOL)', author_email='eric.lebigot@normalesup.org', url='http://uncertainties-python-package.readthedocs.io/', diff --git a/uncertainties/__init__.py b/uncertainties/__init__.py index e5704411..3f871302 100644 --- a/uncertainties/__init__.py +++ b/uncertainties/__init__.py @@ -225,7 +225,7 @@ from .core import __all__ # For a correct help(uncertainties) # Numerical version: -__version_info__ = (3, 1, 2) +__version_info__ = (3, 1, 3) __version__ = '.'.join(map(str, __version_info__)) __author__ = 'Eric O. LEBIGOT (EOL) ' diff --git a/uncertainties/core.py b/uncertainties/core.py index cfba907d..b58544d1 100644 --- a/uncertainties/core.py +++ b/uncertainties/core.py @@ -12,7 +12,7 @@ # Uncertainties can then be calculated by using this local linear # approximation of the original function. -from __future__ import division # Many analytical derivatives depend on this + # Many analytical derivatives depend on this import sys import re @@ -174,7 +174,7 @@ def correlated_values(nom_values, covariance_mat, tags=None): return correlated_values_norm( # !! The following zip() is a bit suboptimal: correlated_values() # separates back the nominal values and the standard deviations: - zip(nom_values, std_devs), + list(zip(nom_values, std_devs)), covariance_mat/norm_vector/norm_vector[:,numpy.newaxis], tags) @@ -244,7 +244,7 @@ def correlated_values_norm(values_with_std_dev, correlation_mat, values_funcs = tuple( AffineScalarFunc( value, - LinearCombination(dict(zip(variables, coords)))) + LinearCombination(dict(list(zip(variables, coords))))) for (coords, value) in zip(transform, nominal_values)) return values_funcs @@ -305,7 +305,7 @@ def partial_derivative(f, arg_ref): # Which set of function parameter contains the variable to be # changed? the positional or the optional keyword arguments? - change_kwargs = isinstance(arg_ref, basestring) + change_kwargs = isinstance(arg_ref, str) def partial_derivative_of_f(*args, **kwargs): """ @@ -553,7 +553,7 @@ def wrap(f, derivatives_args=[], derivatives_kwargs={}): derivatives_all_kwargs = {} - for (name, derivative) in derivatives_kwargs.iteritems(): + for (name, derivative) in derivatives_kwargs.items(): # Optimization: None keyword-argument derivatives are converted # right away to derivatives (instead of doing this every time a @@ -648,7 +648,7 @@ def f_with_affine_output(*args, **kwargs): pos_w_uncert = [index for (index, value) in enumerate(args) if isinstance(value, AffineScalarFunc)] - names_w_uncert = [key for (key, value) in kwargs.iteritems() + names_w_uncert = [key for (key, value) in kwargs.items() if isinstance(value, AffineScalarFunc)] ######################################## @@ -964,25 +964,25 @@ def robust_align(orig_str, fill_char, align_option, width): # Maps some Unicode code points ("-", "+", and digits) to their # superscript version: TO_SUPERSCRIPT = { - 0x2b: u'⁺', - 0x2d: u'⁻', - 0x30: u'⁰', - 0x31: u'¹', - 0x32: u'²', - 0x33: u'³', - 0x34: u'⁴', - 0x35: u'⁵', - 0x36: u'⁶', - 0x37: u'⁷', - 0x38: u'⁸', - 0x39: u'⁹' + 0x2b: '⁺', + 0x2d: '⁻', + 0x30: '⁰', + 0x31: '¹', + 0x32: '²', + 0x33: '³', + 0x34: '⁴', + 0x35: '⁵', + 0x36: '⁶', + 0x37: '⁷', + 0x38: '⁸', + 0x39: '⁹' } # Inverted TO_SUPERSCRIPT table, for use with unicode.translate(): # #! Python 2.7+ can use a dictionary comprehension instead: FROM_SUPERSCRIPT = { - ord(sup): normal for (normal, sup) in TO_SUPERSCRIPT.iteritems()} + ord(sup): normal for (normal, sup) in TO_SUPERSCRIPT.items()} def to_superscript(value): ''' @@ -993,7 +993,7 @@ def to_superscript(value): value -- integer. ''' - return (u'%d' % value).translate(TO_SUPERSCRIPT) + return ('%d' % value).translate(TO_SUPERSCRIPT) def from_superscript(number_str): ''' @@ -1003,12 +1003,12 @@ def from_superscript(number_str): number_str -- basestring object. ''' - return int(unicode(number_str).translate(FROM_SUPERSCRIPT)) + return int(str(number_str).translate(FROM_SUPERSCRIPT)) # Function that transforms an exponent produced by format_num() into # the corresponding string notation (for non-default modes): EXP_PRINT = { - 'pretty-print': lambda common_exp: u'×10%s' % to_superscript(common_exp), + 'pretty-print': lambda common_exp: '×10%s' % to_superscript(common_exp), 'latex': lambda common_exp: r' \times 10^{%d}' % common_exp} # Symbols used for grouping (typically between parentheses) in format_num(): @@ -1403,7 +1403,7 @@ def format_num(nom_val_main, error_main, common_exp, if 'P' in options: # Unicode has priority over LaTeX, so that users with a # Unicode-compatible LaTeX source can use ±: - pm_symbol = u'±' + pm_symbol = '±' elif 'L' in options: pm_symbol = r' \pm ' else: @@ -1544,7 +1544,7 @@ def expand(self): # print "MAINS", main_factor, main_expr if main_expr.expanded(): - for (var, factor) in main_expr.linear_combo.iteritems(): + for (var, factor) in main_expr.linear_combo.items(): derivatives[var] += main_factor*factor else: # Non-expanded form @@ -1700,7 +1700,7 @@ def derivatives(self): # as the result of bool()) don't have a very meaningful # uncertainty unless it is zero, this behavior is fine. - def __nonzero__(self): + def __bool__(self): """ Equivalent to self != 0. """ @@ -1775,7 +1775,7 @@ def error_components(self): # Calculation of the variance: error_components = {} - for (variable, derivative) in self.derivatives.iteritems(): + for (variable, derivative) in self.derivatives.items(): # print "TYPE", type(variable), type(derivative) @@ -1812,7 +1812,7 @@ def std_dev(self): #not need to have their std_dev calculated: only the final #AffineScalarFunc returned to the user does). return CallableStdDev(sqrt(sum( - delta**2 for delta in self.error_components().itervalues()))) + delta**2 for delta in self.error_components().values()))) # Abbreviation (for formulas, etc.): s = std_dev @@ -2413,7 +2413,7 @@ def __setstate__(self, data_dict): """ Hook for the pickle module. """ - for (name, value) in data_dict.iteritems(): + for (name, value) in data_dict.items(): # Contrary to the default __setstate__(), this does not # necessarily save to the instance dictionary (because the # instance might contain slots): @@ -2493,7 +2493,7 @@ def get_ops_with_reflection(): # Conversion to Python functions: ops_with_reflection = {} - for (op, derivatives) in derivatives_list.iteritems(): + for (op, derivatives) in derivatives_list.items(): ops_with_reflection[op] = [ eval("lambda x, y: %s" % expr) for expr in derivatives ] @@ -2531,11 +2531,11 @@ def pow_deriv_1(x, y): # Undefined derivatives are converted to NaN when the function # itself can be calculated: for op in ['pow']: - ops_with_reflection[op] = map(nan_if_exception, - ops_with_reflection[op]) + ops_with_reflection[op] = list(map(nan_if_exception, + ops_with_reflection[op])) - ops_with_reflection['r'+op] = map(nan_if_exception, - ops_with_reflection['r'+op]) + ops_with_reflection['r'+op] = list(map(nan_if_exception, + ops_with_reflection['r'+op])) return ops_with_reflection @@ -2616,7 +2616,7 @@ def _simple_add_deriv(x): } for (op, derivative) in ( - simple_numerical_operators_derivatives.iteritems()): + iter(simple_numerical_operators_derivatives.items())): attribute_name = "__%s__" % op @@ -2636,7 +2636,7 @@ def _simple_add_deriv(x): # Final definition of the operators for AffineScalarFunc objects: # Reversed versions (useful for float*AffineScalarFunc, for instance): - for (op, derivatives) in ops_with_reflection.iteritems(): + for (op, derivatives) in ops_with_reflection.items(): attribute_name = '__%s__' % op # float objects don't exactly have the same attributes between @@ -2918,12 +2918,12 @@ def correlation_matrix(nums_with_uncert): # semantics of some representations (e.g. .1(2.) = .1+/-2, whereas # .1(2) = .1+/-0.2), so just getting the numerical value of the part # in parentheses would not be sufficient. -POSITIVE_DECIMAL_UNSIGNED_OR_NON_FINITE = ur'((\d*)(\.\d*)?|nan|NAN|inf|INF)' +POSITIVE_DECIMAL_UNSIGNED_OR_NON_FINITE = r'((\d*)(\.\d*)?|nan|NAN|inf|INF)' # Regexp for a number with uncertainty (e.g., "-1.234(2)e-6"), where # the uncertainty is optional (in which case the uncertainty is # implicit). The uncertainty can also be nan or NAN: -NUMBER_WITH_UNCERT_RE_STR = ur''' +NUMBER_WITH_UNCERT_RE_STR = r''' ([+-])? # Sign %s # Main number (?:\(%s\))? # Optional uncertainty @@ -2935,12 +2935,12 @@ def correlation_matrix(nums_with_uncert): POSITIVE_DECIMAL_UNSIGNED_OR_NON_FINITE) NUMBER_WITH_UNCERT_RE_MATCH = re.compile( - u"%s$" % NUMBER_WITH_UNCERT_RE_STR, re.VERBOSE).match + "%s$" % NUMBER_WITH_UNCERT_RE_STR, re.VERBOSE).match # Number with uncertainty with a factored exponent (e.g., of the form # (... +/- ...)e10): this is a loose matching, so as to accommodate # for multiple formats: -NUMBER_WITH_UNCERT_GLOBAL_EXP_RE_MATCH = re.compile(ur''' +NUMBER_WITH_UNCERT_GLOBAL_EXP_RE_MATCH = re.compile(r''' \( (?P.*) \) @@ -3012,7 +3012,7 @@ def parse_error_in_parentheses(representation): return (value, uncert_value) # Regexp for catching the two variable parts of -1.2×10⁻¹²: -PRETTY_PRINT_MATCH = re.compile(ur'(.*?)\s*×\s*10(.*)').match +PRETTY_PRINT_MATCH = re.compile(r'(.*?)\s*×\s*10(.*)').match def to_float(value_str): ''' @@ -3089,7 +3089,7 @@ def str_to_number_with_uncert(representation): else: factor = 1 # No global exponential factor - match = re.match(ur'(.*)(?:\+/-|±)(.*)', representation) + match = re.match(r'(.*)(?:\+/-|±)(.*)', representation) if match: (nom_value, uncert) = match.groups() diff --git a/uncertainties/lib1to2/test_1to2.py b/uncertainties/lib1to2/test_1to2.py index de96b5df..615306a6 100644 --- a/uncertainties/lib1to2/test_1to2.py +++ b/uncertainties/lib1to2/test_1to2.py @@ -55,7 +55,7 @@ def check_refactor(refactorer, source, expected): source, expected -- strings (typically with Python code). """ - new = unicode( + new = str( refactorer.refactor_string(support.reformat(source), '')) assert support.reformat(expected) == new, ( @@ -74,7 +74,7 @@ def check_all(fixer, tests): refactorer = support.get_refactorer( fixer_pkg='lib1to2', fixers=[fixer]) - for (input_str, out_str) in tests.items(): + for (input_str, out_str) in list(tests.items()): check_refactor(refactorer, input_str, out_str) def test_fix_std_dev(): @@ -140,7 +140,7 @@ def test_ufloat(): # !! Dictionary comprehension usable with Python 2.7+ (orig.replace('ufloat', 'unc.ufloat'), new.replace('ufloat', 'unc.ufloat')) - for (orig, new) in tests.iteritems())) + for (orig, new) in tests.items())) # Test for space consistency: tests[' t = u.ufloat("3")'] = ' t = u.ufloat_fromstr("3")' @@ -149,7 +149,7 @@ def test_ufloat(): tests.update(dict( # !! Dictionary comprehension usable with Python 2.7+ (orig+'**2', new+'**2') - for (orig, new) in tests.iteritems())) + for (orig, new) in tests.items())) # Exponent test: tests['2**ufloat("3")'] = '2**ufloat_fromstr("3")' @@ -183,13 +183,13 @@ def test_uarray_umatrix(): # !! Dictionary comprehension usable with Python 2.7+ (orig.replace('uarray', 'un.uarray'), new.replace('uarray', 'un.uarray')) - for (orig, new) in tests.iteritems())) + for (orig, new) in tests.items())) # Exponentiation test: tests.update(dict( # !! Dictionary comprehension usable with Python 2.7+ (orig+'**2', new+'**2') - for (orig, new) in tests.iteritems())) + for (orig, new) in tests.items())) # Test for space consistency: tests[' t = u.uarray(args)'] = ' t = u.uarray(*args)' @@ -198,7 +198,7 @@ def test_uarray_umatrix(): tests.update(dict( (orig.replace('uarray', 'umatrix'), new.replace('uarray', 'umatrix')) - for (orig, new) in tests.iteritems())) + for (orig, new) in tests.items())) check_all('uarray_umatrix', tests) diff --git a/uncertainties/test_umath.py b/uncertainties/test_umath.py index 4a6e247c..83a8f89b 100644 --- a/uncertainties/test_umath.py +++ b/uncertainties/test_umath.py @@ -6,7 +6,7 @@ (c) 2010-2016 by Eric O. LEBIGOT (EOL). """ -from __future__ import division + # Standard modules import sys @@ -17,7 +17,7 @@ import uncertainties.core as uncert_core import uncertainties.umath_core as umath_core -import test_uncertainties +from . import test_uncertainties ############################################################################### # Unit tests @@ -244,7 +244,7 @@ def test_math_module(): # 2.6+, ValueError in Python 2.5,...): try: math.log(0) - except Exception, err_math: # "as", for Python 2.6+ + except Exception as err_math: # "as", for Python 2.6+ # Python 3 does not make exceptions local variables: they are # restricted to their except block: err_math_args = err_math.args @@ -252,19 +252,19 @@ def test_math_module(): try: umath_core.log(0) - except exception_class, err_ufloat: # "as", for Python 2.6+ + except exception_class as err_ufloat: # "as", for Python 2.6+ assert err_math_args == err_ufloat.args else: raise Exception('%s exception expected' % exception_class.__name__) try: umath_core.log(ufloat(0, 0)) - except exception_class, err_ufloat: # "as", for Python 2.6+ + except exception_class as err_ufloat: # "as", for Python 2.6+ assert err_math_args == err_ufloat.args else: raise Exception('%s exception expected' % exception_class.__name__) try: umath_core.log(ufloat(0, 1)) - except exception_class, err_ufloat: # "as", for Python 2.6+ + except exception_class as err_ufloat: # "as", for Python 2.6+ assert err_math_args == err_ufloat.args else: raise Exception('%s exception expected' % exception_class.__name__) @@ -309,7 +309,7 @@ def test_power_special_cases(): # 2.6+, ValueError in Python 2.5,...): try: math.pow(0, negative.nominal_value) - except Exception, err_math: # "as", for Python 2.6+ + except Exception as err_math: # "as", for Python 2.6+ # Python 3 does not make exceptions local variables: they are # restricted to their except block: err_math_args = err_math.args @@ -319,7 +319,7 @@ def test_power_special_cases(): try: umath_core.pow(ufloat(0, 0.1), negative) - except exception_class, err: # "as err", for Python 2.6+ + except exception_class as err: # "as err", for Python 2.6+ pass else: raise Exception('%s exception expected' % exception_class.__name__) diff --git a/uncertainties/test_uncertainties.py b/uncertainties/test_uncertainties.py index 87cd54c7..466e3c6c 100644 --- a/uncertainties/test_uncertainties.py +++ b/uncertainties/test_uncertainties.py @@ -8,7 +8,7 @@ (c) 2010-2016 by Eric O. LEBIGOT (EOL). """ -from __future__ import division + # Standard modules @@ -31,7 +31,7 @@ # The following information is useful for making sure that the right # version of Python is running the tests (for instance with the Travis # Continuous Integration system): -print "Testing with Python", sys.version +print("Testing with Python", sys.version) ############################################################################### @@ -154,7 +154,7 @@ def compare_derivatives(func, numerical_derivatives, args = [] for arg_num in range(num_args): if arg_num in integer_arg_nums: - args.append(random.choice(range(-10, 10))) + args.append(random.choice(list(range(-10, 10)))) else: args.append( uncert_core.Variable(random.random()*4-2, 0)) @@ -185,8 +185,8 @@ def compare_derivatives(func, numerical_derivatives, # This message is useful: the user can see that # tests are really performed (instead of not being # performed, silently): - print "Testing derivative #%d of %s at %s" % ( - arg_num, funcname, args_scalar) + print("Testing derivative #%d of %s at %s" % ( + arg_num, funcname, args_scalar)) if not numbers_close(fixed_deriv_value, num_deriv_value, 1e-4): @@ -201,20 +201,20 @@ def compare_derivatives(func, numerical_derivatives, % (arg_num, funcname, args, fixed_deriv_value, num_deriv_value)) - except ValueError, err: # Arguments out of range, or of wrong type + except ValueError as err: # Arguments out of range, or of wrong type # Factorial(real) lands here: if str(err).startswith('factorial'): integer_arg_nums = set([0]) continue # We try with different arguments # Some arguments might have to be integers, for instance: - except TypeError, err: + except TypeError as err: if len(integer_arg_nums) == num_args: raise Exception("Incorrect testing procedure: unable to " "find correct argument values for %s: %s" % (funcname, err)) # Another argument might be forced to be an integer: - integer_arg_nums.add(random.choice(range(num_args))) + integer_arg_nums.add(random.choice(list(range(num_args)))) else: # We have found reasonable arguments, and the test passed: break @@ -337,15 +337,15 @@ def test_ufloat_fromstr(): ## Pretty-print notation: # ± sign, global exponent (not pretty-printed): - u'(3.141±0.001)E+02': (314.1, 0.1), + '(3.141±0.001)E+02': (314.1, 0.1), # ± sign, individual exponent: - u'3.141E+02±0.001e2': (314.1, 0.1), + '3.141E+02±0.001e2': (314.1, 0.1), # ± sign, times symbol, superscript (= full pretty-print): - u'(3.141 ± 0.001) × 10²': (314.1, 0.1), + '(3.141 ± 0.001) × 10²': (314.1, 0.1), # NaN uncertainty: - u'(3.141±nan)E+02': (314.1, float('nan')), + '(3.141±nan)E+02': (314.1, float('nan')), '3.141e+02+/-nan': (314.1, float('nan')), '3.4(nan)e10': (3.4e10, float('nan')), # NaN value: @@ -357,7 +357,7 @@ def test_ufloat_fromstr(): '-3(0.)': (-3, 0) } - for (representation, values) in tests.iteritems(): + for (representation, values) in tests.items(): # Without tag: num = ufloat_fromstr(representation) @@ -419,7 +419,7 @@ def check_op(op, num_args): # by definition, to AffineScalarFunc objects: we first map # possible scalar arguments (used for calculating # derivatives) to AffineScalarFunc objects: - lambda *args: func(*map(uncert_core.to_affine_scalar, args))) + lambda *args: func(*list(map(uncert_core.to_affine_scalar, args)))) compare_derivatives(func, numerical_derivatives, [num_args]) # Operators that take 1 value: @@ -443,7 +443,7 @@ def test_copy(): y = copy.copy(x) assert x != y assert not(x == y) - assert y in y.derivatives.keys() # y must not copy the dependence on x + assert y in list(y.derivatives.keys()) # y must not copy the dependence on x z = copy.deepcopy(x) assert x != z @@ -479,7 +479,7 @@ def test_copy(): gc.collect() - assert y in y.derivatives.keys() + assert y in list(y.derivatives.keys()) ## Classes for the pickling tests (put at the module level, so that ## they can be unpickled): @@ -698,7 +698,7 @@ def random_float(var): try: assert correct_result == getattr(x, op)(y) except AssertionError: - print "Sampling results:", sampled_results + print("Sampling results:", sampled_results) raise Exception("Semantic value of %s %s (%s) %s not" " correctly reproduced." % (x, op, y, correct_result)) @@ -930,7 +930,7 @@ def f_auto_unc(x, y, **kwargs): # Like f_auto_unc, but does not accept numbers with uncertainties: def f(x, y, **kwargs): assert not any(isinstance(value, uncert_core.UFloat) - for value in [x, y] + kwargs.values()) + for value in [x, y] + list(kwargs.values())) return f_auto_unc(x, y, **kwargs) x = uncert_core.ufloat(1, 0.1) @@ -1022,7 +1022,7 @@ def f_auto_unc(x, y, *args, **kwargs): # Like f_auto_unc, but does not accept numbers with uncertainties: def f(x, y, *args, **kwargs): assert not any(isinstance(value, uncert_core.UFloat) - for value in [x, y]+list(args)+kwargs.values()) + for value in [x, y]+list(args)+list(kwargs.values())) return f_auto_unc(x, y, *args, **kwargs) x = uncert_core.ufloat(1, 0.1) @@ -1165,7 +1165,7 @@ def f(x, y, *args, **kwargs): # We make sure that f is not called directly with a number with # uncertainty: - for value in [x, y]+list(args)+kwargs.values(): + for value in [x, y]+list(args)+list(kwargs.values()): assert not isinstance(value, uncert_core.UFloat) return f_auto_unc(x, y, *args, **kwargs) @@ -1510,7 +1510,7 @@ def test_PDG_precision(): 9.99e-324: (2, 1e-323) } - for (std_dev, result) in tests.iteritems(): + for (std_dev, result) in tests.items(): assert uncert_core.PDG_precision(std_dev) == result def test_repr(): @@ -1643,7 +1643,7 @@ def test_format(): # found in Python 2.7: '{:.1%}'.format(0.0055) is '0.5%'. '.1u%': '(42.0+/-0.5)%', '.1u%S': '42.0(5)%', - '%P': u'(42.0±0.5)%' + '%P': '(42.0±0.5)%' }, # Particle Data Group automatic convention, including limit cases: @@ -1714,17 +1714,17 @@ def test_format(): # instead of 1.4 for Python 3.1. The problem does not appear # with 1.2, so 1.2 is used. (-1.2e-12, 0): { - '12.2gPL': ur' -1.2×10⁻¹²± 0', + '12.2gPL': r' -1.2×10⁻¹²± 0', # Pure "width" formats are not accepted by the % operator, # and only %-compatible formats are accepted, for Python < # 2.6: '13S': ' -1.2(0)e-12', - '10P': u'-1.2×10⁻¹²± 0', + '10P': '-1.2×10⁻¹²± 0', 'L': r'\left(-1.2 \pm 0\right) \times 10^{-12}', # No factored exponent, LaTeX '1L': r'-1.2 \times 10^{-12} \pm 0', 'SL': r'-1.2(0) \times 10^{-12}', - 'SP': ur'-1.2(0)×10⁻¹²' + 'SP': r'-1.2(0)×10⁻¹²' }, # Python 3.2 and 3.3 give 1.4e-12*1e+12 = 1.4000000000000001 @@ -1735,7 +1735,7 @@ def test_format(): '15GS': ' -1.2(%s)E-12' % NaN_EFG, 'SL': r'-1.2(\mathrm{nan}) \times 10^{-12}', # LaTeX NaN # Pretty-print priority, but not for NaN: - 'PSL': u'-1.2(\mathrm{nan})×10⁻¹²', + 'PSL': '-1.2(\mathrm{nan})×10⁻¹²', 'L': r'\left(-1.2 \pm \mathrm{nan}\right) \times 10^{-12}', # Uppercase NaN and LaTeX: '.1EL': (r'\left(-1.2 \pm \mathrm{%s}\right) \times 10^{-12}' @@ -1746,8 +1746,8 @@ def test_format(): (3.14e-10, 0.01e-10): { # Character (Unicode) strings: - u'P': u'(3.140±0.010)×10⁻¹⁰', # PDG rules: 2 digits - u'PL': ur'(3.140±0.010)×10⁻¹⁰', # Pretty-print has higher priority + 'P': '(3.140±0.010)×10⁻¹⁰', # PDG rules: 2 digits + 'PL': r'(3.140±0.010)×10⁻¹⁰', # Pretty-print has higher priority # Truncated non-zero uncertainty: '.1e': '(3.1+/-0.0)e-10', '.1eS': '3.1(0.0)e-10' @@ -1977,7 +1977,7 @@ def test_format(): 'S': '-inf(inf)', 'LS': '-\infty(\infty)', 'L': '-\infty \pm \infty', - 'LP': u'-\infty±\infty', + 'LP': '-\infty±\infty', # The following is consistent with Python's own # formatting, which depends on the version of Python: # formatting float("-inf") with format(..., "020") gives @@ -2003,7 +2003,7 @@ def test_format(): 'S': 'nan(inf)', 'LS': '\mathrm{nan}(\infty)', 'L': '\mathrm{nan} \pm \infty', - 'LP': u'\mathrm{nan}±\infty' + 'LP': '\mathrm{nan}±\infty' }, # Leading zeroes in the shorthand notation: @@ -2033,11 +2033,11 @@ def test_format(): except AttributeError: jython_detected = False - for (values, representations) in tests.iteritems(): + for (values, representations) in tests.items(): value = ufloat(*values) - for (format_spec, result) in representations.iteritems(): + for (format_spec, result) in representations.items(): # print "FORMATTING {} WITH '{}'".format(repr(value), format_spec) @@ -2111,8 +2111,8 @@ def test_unicode_format(): x = ufloat(3.14159265358979, 0.25) - assert isinstance(u'Résultat = %s' % x.format(''), unicode) - assert isinstance(u'Résultat = %s' % x.format('P'), unicode) + assert isinstance('Résultat = %s' % x.format(''), str) + assert isinstance('Résultat = %s' % x.format('P'), str) ############################################################################### @@ -2347,7 +2347,7 @@ def test_correlated_values_correlation_mat(): nominal_values = [v.nominal_value for v in (x, y, z)] std_devs = [v.std_dev for v in (x, y, z)] x2, y2, z2 = uncert_core.correlated_values_norm( - zip(nominal_values, std_devs), corr_mat) + list(zip(nominal_values, std_devs)), corr_mat) # arrays_close() is used instead of numbers_close() because # it compares uncertainties too: diff --git a/uncertainties/umath_core.py b/uncertainties/umath_core.py index 46be230d..64871445 100644 --- a/uncertainties/umath_core.py +++ b/uncertainties/umath_core.py @@ -9,7 +9,7 @@ # which functions are visible to the user in umath.py through from # umath import * and Python shell completion. -from __future__ import division # Many analytical derivatives depend on this + # Many analytical derivatives depend on this # Standard modules import math @@ -227,11 +227,11 @@ def wrap_locally_cst_func(func): here, constant). ''' def wrapped_func(*args, **kwargs): - args_float = map(uncert_core.nominal_value, args) + args_float = list(map(uncert_core.nominal_value, args)) # !! In Python 2.7+, dictionary comprehension: {argname:...} kwargs_float = dict( (arg_name, uncert_core.nominal_value(value)) - for (arg_name, value) in kwargs.iteritems()) + for (arg_name, value) in kwargs.items()) return func(*args_float, **kwargs_float) return wrapped_func @@ -257,7 +257,7 @@ def wrapped_func(*args, **kwargs): # that cannot be calculated indicates a non-defined derivative # (the derivatives in fixed_derivatives must be written this way): wrapped_func = uncert_core.wrap( - func, map(uncert_core.nan_if_exception, derivatives)) + func, list(map(uncert_core.nan_if_exception, derivatives))) # !! The same effect could be achieved with globals()[...] = ... setattr(this_module, name, wraps(wrapped_func, func)) diff --git a/uncertainties/unumpy/core.py b/uncertainties/unumpy/core.py index 90ca4f2f..e24a1d10 100644 --- a/uncertainties/unumpy/core.py +++ b/uncertainties/unumpy/core.py @@ -9,7 +9,7 @@ # imports one of the submodules in order to make it available to the # user. -from __future__ import division + # Standard modules: import sys @@ -175,7 +175,7 @@ def wrapped_func(arr, *args, **kwargs): # !!!! This forces an evaluation of the # derivatives!? Isn't this very slow, when # working with a large number of arrays? - variables |= set(element.derivatives.iterkeys()) + variables |= set(element.derivatives.keys()) # If the matrix has no variables, then the function value can be # directly returned: @@ -233,7 +233,7 @@ def wrapped_func(arr, *args, **kwargs): # Update of the list of variables and associated # derivatives, for each element: for (derivative_dict, derivative_value) in ( - zip(derivatives.flat, numerical_deriv.flat)): + list(zip(derivatives.flat, numerical_deriv.flat))): if derivative_value: derivative_dict[var] = derivative_value @@ -384,7 +384,7 @@ def wrapped_func(array_like, *args, **kwargs): for element in array_version.flat: # floats, etc. might be present if isinstance(element, uncert_core.AffineScalarFunc): - variables |= element.derivatives.viewkeys() + variables |= element.derivatives.keys() array_nominal = nominal_values(array_version) # Function value, then derivatives at array_nominal (the @@ -408,7 +408,7 @@ def wrapped_func(array_like, *args, **kwargs): # the variables. derivatives = ( numpy.array( - [{} for _ in xrange(func_nominal_value.size)], dtype=object) + [{} for _ in range(func_nominal_value.size)], dtype=object) .reshape(func_nominal_value.shape)) # Memory-efficient approach. A memory-hungry approach would @@ -418,12 +418,12 @@ def wrapped_func(array_like, *args, **kwargs): # progressively build the matrix of derivatives, by # progressively adding the derivatives with respect to # successive variables. - for (var, deriv_wrt_var) in itertools.izip(variables, + for (var, deriv_wrt_var) in zip(variables, func_then_derivs): # Update of the list of variables and associated # derivatives, for each element: - for (derivative_dict, derivative_value) in itertools.izip( + for (derivative_dict, derivative_value) in zip( derivatives.flat, deriv_wrt_var.flat): if derivative_value: derivative_dict[var] = derivative_value diff --git a/uncertainties/unumpy/test_ulinalg.py b/uncertainties/unumpy/test_ulinalg.py index b72a0e11..10f308d5 100644 --- a/uncertainties/unumpy/test_ulinalg.py +++ b/uncertainties/unumpy/test_ulinalg.py @@ -9,7 +9,7 @@ # Some tests are already performed in test_unumpy (unumpy contains a # matrix inversion, for instance). They are not repeated here. -from __future__ import division + try: import numpy diff --git a/uncertainties/unumpy/test_unumpy.py b/uncertainties/unumpy/test_unumpy.py index 5923dfd3..1215c7eb 100644 --- a/uncertainties/unumpy/test_unumpy.py +++ b/uncertainties/unumpy/test_unumpy.py @@ -6,7 +6,7 @@ (c) 2010-2016 by Eric O. LEBIGOT (EOL). """ -from __future__ import division + # 3rd-party modules: try: