diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc22ff1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +build/ +dist/ +genutil.egg-info/ +tests/__pycache__/ +tests/.last_failure diff --git a/Lib/__init__.py b/Lib/__init__.py index 8b4315a..26dd70b 100644 --- a/Lib/__init__.py +++ b/Lib/__init__.py @@ -21,6 +21,7 @@ import os # noqa import sys # noqa import cdat_info +from .stats_checker import StatisticsError # noqa # udunits bits from .udunits import udunits, addBaseUnit, addDimensionlessUnit, addScaledUnit # noqa diff --git a/Lib/averager.py b/Lib/averager.py index 196726f..0c62e1d 100644 --- a/Lib/averager.py +++ b/Lib/averager.py @@ -11,14 +11,7 @@ class AveragerError (Exception): - def __init__(self, args=None): - """Create an exception""" - self.args = args - - def __str__(self): - """Calculate the string representation""" - return str(self.args) - __repr__ = __str__ + pass def _check_axisoptions(x, axisoptions): @@ -442,7 +435,7 @@ def __check_weightoptions(x, axisoptions, weightoptions): if __DEBUG__: print('axislist = ', axislist) # - if not isinstance(weightoptions, list): + if not isinstance(weightoptions, (list, tuple)): # # We have either 1 axis only or multiple axes and one MV2 of weights # @@ -490,6 +483,11 @@ def __check_weightoptions(x, axisoptions, weightoptions): # # We have multiple axes to deal with each with a weight.... # + + # Ensure we have a mutable list, handles tuple (https://github.com/CDAT/genutil/issues/32 + if not isinstance(weightoptions, list): + weightoptions = list(weightoptions) + for i in range(len(axislist)): weightoptions[i] = __check_each_weight_option( x, axislist[i], axisindex[i], weightoptions[i]) diff --git a/Lib/stats_checker.py b/Lib/stats_checker.py index b663919..c2a978c 100644 --- a/Lib/stats_checker.py +++ b/Lib/stats_checker.py @@ -5,15 +5,7 @@ class StatisticsError(Exception): - def __init__(self, args=None): - """Create an exception""" - self.args = args - - def __str__(self): - """Calculate the string representation""" - return str(self.args) - - __repr__ = __str__ + pass def __makeweights(x, w, axes): diff --git a/tests/test_genutil_averager.py b/tests/test_genutil_averager.py index 3749d57..0504972 100644 --- a/tests/test_genutil_averager.py +++ b/tests/test_genutil_averager.py @@ -6,6 +6,13 @@ import unittest class GENUTIL(unittest.TestCase): + def testError(self): + error = AveragerError("Custom error message") + + print(str(error)) + + self.assertTrue(str(error) == "Custom error message") + def testAverager(self): f=cdms2.open(os.path.join(cdat_info.get_sampledata_path(),'tas_ukmo_con.nc')) x = f('tas') diff --git a/tests/test_genutil_stats_missing.py b/tests/test_genutil_stats_missing.py index 0d1e825..cc3fc0b 100644 --- a/tests/test_genutil_stats_missing.py +++ b/tests/test_genutil_stats_missing.py @@ -4,6 +4,11 @@ import numpy class GENUTIL(unittest.TestCase): + def testError(self): + error = genutil.StatisticsError("Custom error message") + + self.assertTrue(str(error) == "Custom error message") + def testStatsMissing(self): a=MV2.array([1,2,3,4,5],mask=[0,0,1,0,0]) self.assertTrue(numpy.allclose(genutil.statistics.std(a),1.58113883008))