From 842126871df8381c4cc6c32ec099b3870bb732f4 Mon Sep 17 00:00:00 2001 From: andrewgsavage Date: Tue, 2 Apr 2024 22:59:51 +0900 Subject: [PATCH 1/2] remove 1to2 and deprecations (#214) This commit removes: - the 1to2 code and documentation, - the compatability code that handled obsolete function calls, - the deprecations in these calls, - the tests that tested obsolete behaviour --- doc/index.rst | 43 ---- uncertainties/1to2.py | 19 -- uncertainties/core.py | 82 +------ uncertainties/lib1to2/__init__.py | 0 uncertainties/lib1to2/fixes/__init__.py | 0 uncertainties/lib1to2/fixes/fix_std_dev.py | 38 ---- uncertainties/lib1to2/fixes/fix_std_devs.py | 22 -- .../lib1to2/fixes/fix_uarray_umatrix.py | 80 ------- uncertainties/lib1to2/fixes/fix_ufloat.py | 105 --------- uncertainties/lib1to2/test_1to2.py | 207 ------------------ uncertainties/test_uncertainties.py | 66 ------ uncertainties/unumpy/core.py | 31 +-- uncertainties/unumpy/test_unumpy.py | 21 +- 13 files changed, 7 insertions(+), 707 deletions(-) delete mode 100755 uncertainties/1to2.py delete mode 100644 uncertainties/lib1to2/__init__.py delete mode 100644 uncertainties/lib1to2/fixes/__init__.py delete mode 100644 uncertainties/lib1to2/fixes/fix_std_dev.py delete mode 100644 uncertainties/lib1to2/fixes/fix_std_devs.py delete mode 100644 uncertainties/lib1to2/fixes/fix_uarray_umatrix.py delete mode 100644 uncertainties/lib1to2/fixes/fix_ufloat.py delete mode 100644 uncertainties/lib1to2/test_1to2.py diff --git a/doc/index.rst b/doc/index.rst index f6945510..104fe5cf 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -247,49 +247,6 @@ total). :mod:`uncertainties` is thus a **lightweight, portable package** with abundant documentation and tests. -Migration from version 1 to version 2 -===================================== - -Some **incompatible changes** were introduced in version 2 of -:mod:`uncertainties` (see the `version history`_). While the version 2 -line will support the version 1 syntax for some time, it is -recommended to **update existing programs** as soon as possible. This -can be made easier through the provided **automatic updater**. - -The automatic updater works like Python's `2to3 -`_ updater. It can be run -(in a Unix or DOS shell) with: - -.. code-block:: sh - - python -m uncertainties.1to2 - -For example, updating a single Python program can be done with - -.. code-block:: sh - - python -m uncertainties.1to2 -w example.py - -All the Python programs contained under a directory ``Programs`` -(including in nested sub-directories) can be automatically updated -with - -.. code-block:: sh - - python -m uncertainties.1to2 -w Programs - -Backups are automatically created, unless the ``-n`` option is given. - -Some **manual adjustments** might be necessary after running the -updater (incorrectly modified lines, untouched obsolete syntax). - -While the updater creates backup copies by default, it is generally -useful to **first create a backup** of the modified directory, or -alternatively to use some `version control -`_ -system. Reviewing the modifications with a `file comparison tool -`_ might also be useful. - What others say =============== diff --git a/uncertainties/1to2.py b/uncertainties/1to2.py deleted file mode 100755 index 66db72ef..00000000 --- a/uncertainties/1to2.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python - -''' -Fixes code like the 2to3 Python utility, but with fixers from the local fixes -directory. - -(c) 2013 by Eric O. LEBIGOT (EOL). -''' - -# Code inspired by the 2to3 Python code. - -import sys - -if sys.version_info < (2, 6): - sys.exit("Please run this program with Python 2.6+.") - -import lib2to3.main - -sys.exit(lib2to3.main.main('uncertainties.lib1to2.fixes')) diff --git a/uncertainties/core.py b/uncertainties/core.py index 8ed7d433..a5870dfe 100644 --- a/uncertainties/core.py +++ b/uncertainties/core.py @@ -98,25 +98,6 @@ def set_doc_string(func): CONSTANT_TYPES = FLOAT_LIKE_TYPES+(complex,) ############################################################################### - -# Utility for issuing deprecation warnings - -def deprecation(message): - ''' - Warn the user with the given message, by issuing a - DeprecationWarning. - ''' - - # stacklevel = 3 points to the original user call (not to the - # function from this module that called deprecation()). - # DeprecationWarning is ignored by default: not used. - - warnings.warn('Obsolete: %s Code can be automatically updated with' - ' python -m uncertainties.1to2 -w ProgramDirectory.' - % message, stacklevel=3) - -############################################################################### - ## Definitions that depend on the availability of NumPy: @@ -934,21 +915,6 @@ def PDG_precision(std_dev): # used instead of the % formatting operator, if available: robust_format = format -class CallableStdDev(float): - ''' - Class for standard deviation results, which used to be - callable. Provided for compatibility with old code. Issues an - obsolescence warning upon call. - ''' - - # This class is a float. It must be set to the standard deviation - # upon construction. - - def __call__ (self): - deprecation('the std_dev attribute should not be called' - ' anymore: use .std_dev instead of .std_dev().') - return self - # Exponent letter: the keys are the possible main_fmt_type values of # format_num(): EXP_LETTERS = {'f': 'e', 'F': 'E'} @@ -1843,7 +1809,7 @@ def std_dev(self): #std_dev value (in fact, many intermediate AffineScalarFunc do #not need to have their std_dev calculated: only the final #AffineScalarFunc returned to the user does). - return CallableStdDev(sqrt(sum( + return float(sqrt(sum( delta**2 for delta in self.error_components().values()))) # Abbreviation (for formulas, etc.): @@ -2798,13 +2764,7 @@ def std_dev(self, std_dev): if std_dev < 0 and not isinfinite(std_dev): raise NegativeStdDev("The standard deviation cannot be negative") - self._std_dev = CallableStdDev(std_dev) - - # Support for legacy method: - def set_std_dev(self, value): # Obsolete - deprecation('instead of set_std_dev(), please use' - ' .std_dev = ...') - self.std_dev = value + self._std_dev = float(std_dev) # The following method is overridden so that we can represent the tag: def __repr__(self): @@ -3263,21 +3223,9 @@ def ufloat(nominal_value, std_dev=None, tag=None): """ Return a new random variable (Variable object). - The only non-obsolete use is: - - ufloat(nominal_value, std_dev), - ufloat(nominal_value, std_dev, tag=...). - Other input parameters are temporarily supported: - - - ufloat((nominal_value, std_dev)), - - ufloat((nominal_value, std_dev), tag), - - ufloat(str_representation), - - ufloat(str_representation, tag). - - Valid string representations str_representation are listed in - the documentation for ufloat_fromstr(). - nominal_value -- nominal value of the random variable. It is more meaningful to use a value close to the central value or to the mean. This value is propagated by mathematical operations as if it @@ -3292,28 +3240,4 @@ def ufloat(nominal_value, std_dev=None, tag=None): error_components() method). """ - try: - # Standard case: - return Variable(nominal_value, std_dev, tag=tag) - # Exception types raised by, respectively: tuple or string that - # can be converted through float() (case of a number with no - # uncertainty), and string that cannot be converted through - # float(): - except (TypeError, ValueError): - - if tag is not None: - tag_arg = tag # tag keyword used: - else: - tag_arg = std_dev # 2 positional arguments form - - try: - final_ufloat = ufloat_obsolete(nominal_value, tag_arg) - except: # The input is incorrect, not obsolete - raise - else: - # Obsolete, two-argument call: - deprecation( - 'either use ufloat(nominal_value, std_dev),' - ' ufloat(nominal_value, std_dev, tag), or the' - ' ufloat_fromstr() function, for string representations.') - return final_ufloat + return Variable(nominal_value, std_dev, tag=tag) \ No newline at end of file diff --git a/uncertainties/lib1to2/__init__.py b/uncertainties/lib1to2/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/uncertainties/lib1to2/fixes/__init__.py b/uncertainties/lib1to2/fixes/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/uncertainties/lib1to2/fixes/fix_std_dev.py b/uncertainties/lib1to2/fixes/fix_std_dev.py deleted file mode 100644 index fd15912b..00000000 --- a/uncertainties/lib1to2/fixes/fix_std_dev.py +++ /dev/null @@ -1,38 +0,0 @@ -''' -Fixer for lib2to3. - -Transforms .std_dev() calls into .std_dev attribute access. - -(c) 2013 by Eric O. LEBIGOT. -''' - -from lib2to3.fixer_base import BaseFix -from lib2to3.fixer_util import Name, Assign - -class FixStdDev(BaseFix): - - PATTERN = """ - power< any* trailer< '.' 'std_dev' > trailer< '(' ')' > > - | - power< any* trailer< '.' 'set_std_dev' > trailer< '(' set_arg=any ')' > > - """ - - def transform(self, node, results): - - if 'set_arg' in results: # Case of .set_std_dev() - - # set_std_dev => std_dev - attribute = node.children[-2] # .set_std_dev - attribute.children[1].replace(Name('std_dev')) - - # Call "(arg)": removed - node.children[-1].remove() - - # Replacement by an assignment: - node.replace(Assign(node.clone(), results['set_arg'].clone())) - - else: - # '.std_dev' is followed by a call with no argument: the call - # is removed: - node.children[-1].remove() - diff --git a/uncertainties/lib1to2/fixes/fix_std_devs.py b/uncertainties/lib1to2/fixes/fix_std_devs.py deleted file mode 100644 index 31afaf7e..00000000 --- a/uncertainties/lib1to2/fixes/fix_std_devs.py +++ /dev/null @@ -1,22 +0,0 @@ -''' -Fixer for lib2to3. - -Transform .std_devs() calls into .std_devs attribute access. - -(c) 2016 by Eric O. LEBIGOT. -''' - -from lib2to3.fixer_base import BaseFix -from lib2to3.fixer_util import Name, Assign - -class FixStdDevs(BaseFix): - - PATTERN = """ - power< any* trailer< '.' 'std_devs' > trailer< '(' ')' > > - """ - - def transform(self, node, results): - - # '.std_dev' is followed by a call with no argument: the call - # is removed: - node.children[-1].remove() diff --git a/uncertainties/lib1to2/fixes/fix_uarray_umatrix.py b/uncertainties/lib1to2/fixes/fix_uarray_umatrix.py deleted file mode 100644 index a47284ad..00000000 --- a/uncertainties/lib1to2/fixes/fix_uarray_umatrix.py +++ /dev/null @@ -1,80 +0,0 @@ -''' -Fixer for lib2to3. - -Transforms uarray(tuple) into uarray(nominal_values, std_devs) and -uarray(single_arg) into uarray(*single_arg). - -(c) 2013 by Eric O. LEBIGOT (EOL). -''' - -from lib2to3.fixer_base import BaseFix -from lib2to3.fixer_util import String, ArgList, Comma, syms - -############################################################################### -# lib2to3 grammar parts. - -#! Warning: indentation is meaningful! - -# (tuple): -tuple_call = """ - trailer< '(' - atom< '(' testlist_gexp< arg0=any ',' arg1=any > ')' > - ')' >""" - - -############################################################################### - -class FixUarrayUmatrix(BaseFix): - - # Non dotted access, then dotted access. - # Tuple call, then single-argument call - PATTERN = """ - power< 'uarray' {tuple_call} any* > - | - power< object=NAME trailer< '.' 'uarray' > {tuple_call} any* > - | - power< 'uarray' trailer< '(' args=any ')' > any* > - | - power< object=NAME trailer< '.' 'uarray' > - trailer< '(' args=any ')' > - any* > - """.format(tuple_call=tuple_call) - - # Same pattern, for umatrix(): - PATTERN = '{}|{}'.format(PATTERN, PATTERN.replace('uarray', 'umatrix')) - - def transform(self, node, results): - - if 'object' in results: # If dotted access: unc.uarray() - args = node.children[2] - else: - args = node.children[1] - - if 'args' in results: # Non-tuple argument - - # A star will be inserted in from of the single argument: - - # ! The following keeps spaces in front of the argument, - # if any (but this is safer than adding forcefully a star - # in front of the value of the argument: the argument can - # be a name (where it works), but also anything else, - # including a lib2to3.pytree.Node that has no value.) This - # is OK, as the syntax f(* (2, 1)) is valid. - - args_node = results['args'] - - # We must make sure that there is a single argument: - if args_node.type == syms.arglist: - return # Nothing modified - - # Single argument (in position 1): - new_args = [String('*'), args.children[1].clone()] - - else: # Tuple argument - - # New arguments: - new_args = [results['arg0'].clone(), - Comma(), results['arg1'].clone()] - - # Argument list update: - args.replace(ArgList(new_args)) diff --git a/uncertainties/lib1to2/fixes/fix_ufloat.py b/uncertainties/lib1to2/fixes/fix_ufloat.py deleted file mode 100644 index a6e92f7f..00000000 --- a/uncertainties/lib1to2/fixes/fix_ufloat.py +++ /dev/null @@ -1,105 +0,0 @@ -''' -Fixer for lib2to3. - -Transforms ufloat(tuple,...) and ufloat(string,...) into -ufloat(nominal_value, std_dev,...) and ufloat_fromstr - -(c) 2013 by Eric O. LEBIGOT. -''' - -from lib2to3.fixer_base import BaseFix -from lib2to3.fixer_util import ArgList, Call, Comma, Name, syms - -############################################################################### -# lib2to3 grammar parts. - -#! Warning: indentation is meaningful! - -# (tuple): -tuple_call = """ - trailer< '(' - atom< '(' testlist_gexp< arg0=any ',' arg1=any > ')' > - ')' >""" - -# (tuple, any): -tuple_any_call = """ - trailer< '(' - arglist< - atom< '(' testlist_gexp< arg0=any ',' arg1=any > ')' > - ',' tag=any - > - ')' >""" - - -############################################################################### - -class FixUfloat(BaseFix): - - # Non dotted access, then dotted access. - # Tuple call, then string call. - # No-tag call, then tag call. - PATTERN = """ - power< 'ufloat' {tuple_call} any* > - | - power< 'ufloat' {tuple_any_call} any* > - | - power< 'ufloat' trailer< '(' string=STRING ')' > any* > - | - power< 'ufloat' trailer< '(' - arglist< - string=STRING - ',' tag=any - > - ')' > any* > - | - power< object=NAME trailer< '.' 'ufloat' > {tuple_call} any* > - | - power< object=NAME trailer< '.' 'ufloat' > {tuple_any_call} any* > - | - power< object=NAME trailer< '.' 'ufloat' > - trailer< '(' string=STRING ')' > - any* > - | - power< object=NAME trailer< '.' 'ufloat' > - trailer< '(' arglist< string=STRING ',' tag=any > ')' > - any* > - """.format(tuple_call=tuple_call, - tuple_any_call=tuple_any_call) - - - def transform(self, node, results): - - # Handling of the first argument: - - if 'string' in results: # String as first argument - - new_func_name = 'ufloat_fromstr' - - # New arguments: - new_args=[results['string'].clone()] - - else: # Tuple as first argument - - new_func_name = 'ufloat' - - # New arguments: - new_args = [results['arg0'].clone(), - Comma(), results['arg1'].clone()] - - # Handling of the second argument (call with a tag): - if 'tag' in results: - new_args.extend([Comma(), results['tag'].clone()]) - - if 'object' in results: # If dotted access: unc.ufloat() - func_name = node.children[1].children[1] - args = node.children[2] - else: - func_name = node.children[0] - args = node.children[1] - - # Function name update: - func_name.value = new_func_name - #! func_name.changed() # Necessary when only .value is changed - - # Argument list update: - args.replace(ArgList(new_args)) diff --git a/uncertainties/lib1to2/test_1to2.py b/uncertainties/lib1to2/test_1to2.py deleted file mode 100644 index f23f8cc4..00000000 --- a/uncertainties/lib1to2/test_1to2.py +++ /dev/null @@ -1,207 +0,0 @@ -#!/usr/bin/env python - -''' -Unit tests for the uncertainties.lib1to2 code update package. - -Meant to be run through nosetests. - -(c) 2013-2020 by Eric O. LEBIGOT (EOL). -''' - -# Code inspired by: -# -# - lib2to3.tests.test_fixers.py - -from builtins import str -import sys -import os - -# !! Would it be possible to use an import hook so as to stop the -# import if the Python version is not high enough, instead of having -# like here a whole indented block? - - -if sys.version_info < (2, 7) or "TRAVIS" in os.environ or "APPVEYOR" in os.environ: - - # This package uses lib2to3, which requires Python 2.6+. - - # lib2to3.tests.support is missing from 2.7.3 Travis Python packages. - - # !! Nosetests for Python 2.6 also fails (it looks like it tries - # to run tests via lib2to3/tests/test_refactor.py): - - pass - -else: - - import os - try: - # lib2to3 test support seems to have moved to a new place in 2013: - import test.test_lib2to3.support as support - except ImportError: - # Pre-~2013 path for lib2to3 test support - import lib2to3.tests.support as support - - # The lib1to2.fixes package given to lib2to3 is the *local* package - # (not to another installed module). This is important for the - # __import__() used via support.get_refactorer(). - sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) - - def check_refactor(refactorer, source, expected): - """ - Raises an AssertionError if the given - lib2to3.refactor.RefactoringTool does not refactor 'source' into - 'expected'. - - source, expected -- strings (typically with Python code). - """ - - # !! str() is from future's builtins and is only needed for Python 2, - # where it is mostly equivalent to unicode(): - new = str( - refactorer.refactor_string(support.reformat(source), '')) - - assert support.reformat(expected) == new, ( - "Refactoring failed: '{}' => '{}' instead of '{}'".format( - source, new.strip(), expected)) - - # print 'Checked:', source, '=>', expected - - def check_all(fixer, tests): - ''' - Takes a fixer name (module from fixes) and a mapping that maps - code using the obsolete syntax into updated code, and checks - whether the code is correctly updated. - ''' - - refactorer = support.get_refactorer( - fixer_pkg='lib1to2', fixers=[fixer]) - - for (input_str, out_str) in tests.items(): - check_refactor(refactorer, input_str, out_str) - - def test_fix_std_dev(): - 'Tests the transformation of std_dev() into std_dev.' - - - tests = { - 'x.std_dev()': 'x.std_dev', - 'y.std_dev(); unc.std_dev(z)': 'y.std_dev; unc.std_dev(z)', - 'uncertainties.std_dev(x)': 'uncertainties.std_dev(x)', - 'std_dev(x)': 'std_dev(x)', - 'obj.x.std_dev()': 'obj.x.std_dev', - - """ - long_name.std_dev( - # No argument! - )""": - """ - long_name.std_dev""", - - # set_std_dev => .std_dev: - 'x.set_std_dev(3)': 'x.std_dev = 3', - 'y = set_std_dev(3)': 'y = set_std_dev(3)', # None - 'func = x.set_std_dev': 'func = x.set_std_dev', - 'obj.x.set_std_dev(sin(y))': 'obj.x.std_dev = sin(y)' - } - - check_all('std_dev', tests) - - def test_ufloat(): - ''' - Test of the transformation of ufloat(tuple,...) and - ufloat(string,...) into ufloat(nominal_value, std_dev, tag=...). - ''' - - tests = { - # Tuples: - 'ufloat((3, 0.14))': 'ufloat(3, 0.14)', - 'ufloat((3, 0.14), "pi")': 'ufloat(3, 0.14, "pi")', - "ufloat((3, 0.14), 'pi')": "ufloat(3, 0.14, 'pi')", - "x = ufloat((3, 0.14), tag='pi')": "x = ufloat(3, 0.14, tag='pi')", - - # Simple expressions that can be transformed: - 'ufloat((n, s), tag="var")': 'ufloat(n, s, tag="var")', - - # Simple expressions that cannot be transformed automatically: - 'ufloat(str_repr, tag="var")': 'ufloat(str_repr, tag="var")', - 'ufloat(*tuple_repr, tag="var")': 'ufloat(*tuple_repr, tag="var")', - 'ufloat(*t[0, 0])': 'ufloat(*t[0, 0])', - - # Strings: - 'ufloat("-1.23(3.4)")': 'ufloat_fromstr("-1.23(3.4)")', - "ufloat('-1.23(3.4)')": "ufloat_fromstr('-1.23(3.4)')", - 'ufloat("-1.23(3.4)", "var")': - 'ufloat_fromstr("-1.23(3.4)", "var")', - 'ufloat("-1.23(3.4)", tag="var")': - 'ufloat_fromstr("-1.23(3.4)", tag="var")' - - } - - # Automatic addition of a dotted access: - tests.update(dict( - # !! Dictionary comprehension usable with Python 2.7+ - (orig.replace('ufloat', 'unc.ufloat'), - new.replace('ufloat', 'unc.ufloat')) - for (orig, new) in tests.items())) - - # Test for space consistency: - tests[' t = u.ufloat("3")'] = ' t = u.ufloat_fromstr("3")' - - # Exponentiation test: - tests.update(dict( - # !! Dictionary comprehension usable with Python 2.7+ - (orig+'**2', new+'**2') - for (orig, new) in tests.items())) - - # Exponent test: - tests['2**ufloat("3")'] = '2**ufloat_fromstr("3")' - - # Opposite test: - tests['-ufloat("3")'] = '-ufloat_fromstr("3")' - - check_all('ufloat', tests) - - def test_uarray_umatrix(): - ''' - Test of the transformation of uarray(tuple,...) into - uarray(nominal_values, std_devs). Also performs the same tests - on umatrix(). - ''' - - tests = { - 'uarray((arange(3), std_devs))': 'uarray(arange(3), std_devs)', - 'uarray(tuple_arg)': 'uarray(*tuple_arg)', - # Unmodified, correct code: - 'uarray(values, std_devs)': 'uarray(values, std_devs)', - # Spaces tests: - 'uarray( ( arange(3), std_devs ) ) ': - 'uarray( arange(3), std_devs) ', - 'uarray( tuple_arg )': 'uarray(* tuple_arg)' - - } - - # Automatic addition of a dotted access: - tests.update(dict( - # !! Dictionary comprehension usable with Python 2.7+ - (orig.replace('uarray', 'un.uarray'), - new.replace('uarray', 'un.uarray')) - 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.items())) - - # Test for space consistency: - tests[' t = u.uarray(args)'] = ' t = u.uarray(*args)' - - # Same tests, but for umatrix: - tests.update(dict( - (orig.replace('uarray', 'umatrix'), - new.replace('uarray', 'umatrix')) - for (orig, new) in tests.items())) - - check_all('uarray_umatrix', tests) - diff --git a/uncertainties/test_uncertainties.py b/uncertainties/test_uncertainties.py index c5ed4ccc..f37d0bbe 100644 --- a/uncertainties/test_uncertainties.py +++ b/uncertainties/test_uncertainties.py @@ -250,39 +250,6 @@ def test_value_construction(): assert x.std_dev == 0.14 assert x.tag == 'pi' - ## Comparison with the obsolete tuple form: - - # The following tuple is stored in a variable instead of being - # repeated in the calls below, so that the automatic code update - # does not replace ufloat((3, 0.14)) by ufloat(3, 14): the goal - # here is to make sure that the obsolete form gives the same - # result as the new form. - - representation = (3, 0.14) # Obsolete representation - - x = ufloat(3, 0.14) - x2 = ufloat(representation) # Obsolete - assert x.nominal_value == x2.nominal_value - assert x.std_dev == x2.std_dev - assert x.tag is None - assert x2.tag is None - - # With tag as positional argument: - x = ufloat(3, 0.14, "pi") - x2 = ufloat(representation, "pi") # Obsolete - assert x.nominal_value == x2.nominal_value - assert x.std_dev == x2.std_dev - assert x.tag == 'pi' - assert x2.tag == 'pi' - - # With tag keyword: - x = ufloat(3, 0.14, tag="pi") - x2 = ufloat(representation, tag="pi") # Obsolete - assert x.nominal_value == x2.nominal_value - assert x.std_dev == x2.std_dev - assert x.tag == 'pi' - assert x2.tag == 'pi' - # Negative standard deviations should be caught in a nice way # (with the right exception): try: @@ -290,12 +257,6 @@ def test_value_construction(): except uncert_core.NegativeStdDev: pass - try: - # Obsolete form: - x = ufloat((3, -0.1)) - except uncert_core.NegativeStdDev: - pass - ## Incorrect forms should not raise any deprecation warning, but ## raise an exception: @@ -389,25 +350,6 @@ def test_ufloat_fromstr(): assert numbers_close(num.std_dev, values[1]) assert num.tag == 'test variable' - ## Obsolete forms - - num = ufloat(representation) # Obsolete - assert numbers_close(num.nominal_value, values[0]) - assert numbers_close(num.std_dev, values[1]) - assert num.tag is None - - # Call with a tag list argument: - num = ufloat(representation, 'test variable') # Obsolete - assert numbers_close(num.nominal_value, values[0]) - assert numbers_close(num.std_dev, values[1]) - assert num.tag == 'test variable' - - # Call with a tag keyword argument: - num = ufloat(representation, tag='test variable') # Obsolete - assert numbers_close(num.nominal_value, values[0]) - assert numbers_close(num.std_dev, values[1]) - assert num.tag == 'test variable' - ############################################################################### # Test of correctness of the fixed (usually analytical) derivatives: @@ -742,14 +684,6 @@ def test_logic(): assert bool(z) == True assert bool(t) == True # Only infinitseimal neighborhood are used -def test_obsolete(): - 'Tests some obsolete creation of number with uncertainties' - x = ufloat(3, 0.1) - # Obsolete function, protected against automatic modification: - x.set_std_dev.__call__(0.2) # Obsolete - - x_std_dev = x.std_dev - assert x_std_dev() == 0.2 # Obsolete call def test_basic_access_to_data(): "Access to data from Variable and AffineScalarFunc objects." diff --git a/uncertainties/unumpy/core.py b/uncertainties/unumpy/core.py index 3507db4d..54addf06 100644 --- a/uncertainties/unumpy/core.py +++ b/uncertainties/unumpy/core.py @@ -25,7 +25,6 @@ # Local modules: import uncertainties.umath_core as umath_core import uncertainties.core as uncert_core -from uncertainties.core import deprecation __all__ = [ # Factory functions: @@ -285,8 +284,7 @@ def uarray(nominal_values, std_devs=None): """ if std_devs is None: # Obsolete, single tuple argument call - deprecation('uarray() should now be called with two arguments.') - (nominal_values, std_devs) = nominal_values + raise TypeError('uarray() should be called with two arguments.') return (numpy.vectorize( # ! Looking up uncert_core.Variable beforehand through @@ -573,28 +571,6 @@ def pinv(array_like, rcond=pinv_default): ########## Matrix class -class CallableStdDevs(numpy.matrix): - ''' - Class for standard deviation results, which used to be - callable. Provided for compatibility with old code. Issues an - obsolescence warning upon call. - - New objects must be created by passing an existing - ''' - - def __new__(cls, matrix): - # The following prevents a copy of the original matrix, which - # could be expensive, and is unnecessary (the CallableStdDevs - # is just a wrapping around the original matrix, which can be - # modified): - matrix.__class__ = cls - return matrix - - def __call__ (self): - deprecation('the std_devs attribute should not be called' - ' anymore: use .std_devs instead of .std_devs().') - return self - class matrix(numpy.matrix): # The name of this class is the same as NumPy's, which is why it # does not follow PEP 8. @@ -639,7 +615,7 @@ def nominal_values(self): # the first ones to have such methods? @property def std_devs(self): - return CallableStdDevs(std_devs(self)) + return numpy.matrix(std_devs(self)) def umatrix(nominal_values, std_devs=None): """ @@ -653,8 +629,7 @@ def umatrix(nominal_values, std_devs=None): """ if std_devs is None: # Obsolete, single tuple argument call - deprecation('umatrix() should now be called with two arguments.') - (nominal_values, std_devs) = nominal_values + raise TypeError('umatrix() should be called with two arguments.') return uarray(nominal_values, std_devs).view(matrix) diff --git a/uncertainties/unumpy/test_unumpy.py b/uncertainties/unumpy/test_unumpy.py index 5923dfd3..5e2147a5 100644 --- a/uncertainties/unumpy/test_unumpy.py +++ b/uncertainties/unumpy/test_unumpy.py @@ -309,23 +309,4 @@ def test_array_comparisons(): # For matrices, 1D arrays are converted to 2D arrays: mat = unumpy.umatrix([1, 2], [1, 4]) - assert numpy.all((mat == [mat[0,0], 4]) == [True, False]) - -def test_obsolete(): - 'Test of obsolete functions' - - # The new and old calls should give the same results: - - # The unusual syntax is here to protect against automatic code - # update: - arr_obs = unumpy.uarray.__call__(([1, 2], [1, 4])) # Obsolete call - arr = unumpy.uarray([1, 2], [1, 4]) - assert arrays_close(arr_obs, arr) - - # The new and old calls should give the same results: - - # The unusual syntax is here to protect against automatic code - # update: - mat_obs = unumpy.umatrix.__call__(([1, 2], [1, 4])) # Obsolete call - mat = unumpy.umatrix([1, 2], [1, 4]) - assert arrays_close(mat_obs, mat) + assert numpy.all((mat == [mat[0,0], 4]) == [True, False]) \ No newline at end of file From 57e2a20b52de934f4a2e52aa8fa9b0f2ad7261d0 Mon Sep 17 00:00:00 2001 From: Will Riley Date: Tue, 2 Apr 2024 21:36:46 +0200 Subject: [PATCH 2/2] Removed unused imported modules from tests. (#210) Removed unused imports in tests. Co-authored-by: andrewgsavage --- uncertainties/test_umath.py | 1 - uncertainties/test_uncertainties.py | 1 - 2 files changed, 2 deletions(-) diff --git a/uncertainties/test_umath.py b/uncertainties/test_umath.py index 687c2028..c8555e7c 100644 --- a/uncertainties/test_umath.py +++ b/uncertainties/test_umath.py @@ -10,7 +10,6 @@ from __future__ import absolute_import # Standard modules -import sys import math # Local modules: diff --git a/uncertainties/test_uncertainties.py b/uncertainties/test_uncertainties.py index f37d0bbe..79c1db90 100644 --- a/uncertainties/test_uncertainties.py +++ b/uncertainties/test_uncertainties.py @@ -18,7 +18,6 @@ from builtins import map from builtins import range import copy -import weakref import math from math import isnan, isinf import random