Skip to content

Commit

Permalink
Remove some <py3.3 code (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage authored Jul 13, 2024
1 parent 64e7320 commit 9e0ba9a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 45 deletions.
12 changes: 2 additions & 10 deletions uncertainties/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
from __future__ import division # Many analytical derivatives depend on this

from builtins import str, zip, range, object
from math import sqrt, isnan, isinf # Optimization: no attribute look-up

try:
from math import isinfinite # !! Python 3.2+
except ImportError:

def isinfinite(x):
return isinf(x) or isnan(x)

from math import sqrt, isfinite # Optimization: no attribute look-up

import copy
import collections
Expand Down Expand Up @@ -790,7 +782,7 @@ def std_dev(self, std_dev):
# (Note: if NaN < 0 is False, there is no need to test
# separately for NaN. But this is not guaranteed, even if it
# should work on most platforms.)
if std_dev < 0 and not isinfinite(std_dev):
if std_dev < 0 and isfinite(std_dev):
raise NegativeStdDev("The standard deviation cannot be negative")

self._std_dev = float(std_dev)
Expand Down
61 changes: 28 additions & 33 deletions uncertainties/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,44 +168,39 @@ def pow_deriv_1(x, y):
modified_operators = []
modified_ops_with_reflection = []

# Custom versions of some operators (instead of extending some float
# __*__ operators to AffineScalarFunc, the operators in custom_ops
# are used):
if sys.version_info < (3,):
custom_ops = {}

else:
# !!! This code is not run by the tests. It would be nice to have
# it be tested.
def no_complex_result(func):
"""
Return a function that does like func, but that raises a
ValueError if the result is complex.
"""
# !!! This code is not run by the tests. It would be nice to have
# it be tested.
def no_complex_result(func):
"""
Return a function that does like func, but that raises a
ValueError if the result is complex.
"""

def no_complex_func(*args, **kwargs):
"""
Like %s, but raises a ValueError exception if the result
is complex.
""" % func.__name__
def no_complex_func(*args, **kwargs):
"""
Like %s, but raises a ValueError exception if the result
is complex.
""" % func.__name__

value = func(*args, **kwargs)
if isinstance(value, complex):
raise ValueError(
"The uncertainties module does not handle" " complex results"
)
else:
return value

value = func(*args, **kwargs)
if isinstance(value, complex):
raise ValueError(
"The uncertainties module does not handle" " complex results"
)
else:
return value
return no_complex_func

return no_complex_func

# This module does not handle uncertainties on complex numbers:
# complex results for the nominal value of some operations cannot
# be calculated with an uncertainty:
custom_ops = {
"pow": no_complex_result(float.__pow__),
"rpow": no_complex_result(float.__rpow__),
}
# This module does not handle uncertainties on complex numbers:
# complex results for the nominal value of some operations cannot
# be calculated with an uncertainty:
custom_ops = {
"pow": no_complex_result(float.__pow__),
"rpow": no_complex_result(float.__rpow__),
}


def add_arithmetic_ops(cls):
Expand Down
2 changes: 0 additions & 2 deletions uncertainties/unumpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# imports one of the submodules in order to make it available to the
# user.

from __future__ import division

# Standard modules:
from builtins import next
from builtins import zip
Expand Down

0 comments on commit 9e0ba9a

Please sign in to comment.