From 2c68e946ddd12cad0e0758019b5f4e9f0fd158c2 Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 21 Oct 2015 18:03:13 -0700 Subject: [PATCH 1/8] completely fix test_uniqueIndex methods --- wqio/tests/utils_tests/misc_tests.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/wqio/tests/utils_tests/misc_tests.py b/wqio/tests/utils_tests/misc_tests.py index 1eb777d9..b01695a5 100644 --- a/wqio/tests/utils_tests/misc_tests.py +++ b/wqio/tests/utils_tests/misc_tests.py @@ -97,30 +97,31 @@ def test_stringify_None(self): class test_uniqueIndex(object): - def setup(): + def setup(self): dates = range(5) params = list('ABCDE') locations = ['Inflow', 'Outflow'] + dual = [] for d in dates: for p in params: for loc in locations: dual.append([d,p,loc]) - + dual_array = np.array(dual) index = pandas.MultiIndex.from_arrays([dual_array[:,0], - dual_array[:,1], - dual_array[:,2]]) + dual_array[:,1], + dual_array[:,2]]) index.names = ['date', 'param', 'loc'] - self.data = pandas.DataFrame(np.range.normal(size=len(index)), index=index) + self.data = pandas.DataFrame(np.random.normal(size=len(index)), index=index) - def test_getUniqueDataframeIndexVal(): - test = misc.getUniqueDataframeIndexVal(self.data.select(lambda x: x[0]=='0'), 'date') - known = '0' - nt.assert_equal(test, known) + def test_getUniqueDataframeIndexVal(self): + test = misc.getUniqueDataframeIndexVal(self.data.select(lambda x: x[0]=='0'), 'date') + known = '0' + nt.assert_equal(test, known) - @nptest.raises(ValueError) - def test_getUniqueDataframeIndexVal_error(): - misc.getUniqueDataframeIndexVal(self.data, 'date') + @nptest.raises(ValueError) + def test_getUniqueDataframeIndexVal_error(self): + misc.getUniqueDataframeIndexVal(self.data, 'date') class test_redefineIndexLevel(object): From b9612aa1002333ab9865e165eed8698201f03b48 Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 21 Oct 2015 18:05:02 -0700 Subject: [PATCH 2/8] exclude progress bar from coverage --- wqio/utils/misc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wqio/utils/misc.py b/wqio/utils/misc.py index 13fe08f0..dd8ef0b1 100644 --- a/wqio/utils/misc.py +++ b/wqio/utils/misc.py @@ -201,8 +201,7 @@ def stringify(value, fmt, attribute=None): return fmt % quantity - -class ProgressBar: +class ProgressBar: # pragma: no cover def __init__(self, sequence, width=50, labels=None, labelfxn=None): '''Progress bar for notebookes: From 5fc4aabf4c562e123cdb46fc09ded674ff92be7e Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 21 Oct 2015 18:07:49 -0700 Subject: [PATCH 3/8] remove unused (and not implemented) functions --- wqio/core/features.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/wqio/core/features.py b/wqio/core/features.py index 8ae8070d..5c923374 100644 --- a/wqio/core/features.py +++ b/wqio/core/features.py @@ -34,14 +34,6 @@ } -def sanitizeTexParam(x): - return x - - -def sanitizeTexUnit(x): - return x - - class Parameter(object): def __init__(self, name, units, usingTex=False): """ Class representing a single analytical parameter (pollutant). From d133962faf89d4235be8e0889bdca163a413800f Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 21 Oct 2015 18:10:38 -0700 Subject: [PATCH 4/8] remove deprecated filtered data props and methods --- wqio/core/features.py | 47 ------------------------------------------- 1 file changed, 47 deletions(-) diff --git a/wqio/core/features.py b/wqio/core/features.py index 5c923374..6025ba45 100644 --- a/wqio/core/features.py +++ b/wqio/core/features.py @@ -94,10 +94,6 @@ def paramunit(self, usecomma=False): else: paramunit = '{0} ({1})' - #if self.usingTex: - # n = sanitizeTexParam(self.name) - # u = sanitizeTexUnit(self.units) - #else: n = self.name u = self.units @@ -274,11 +270,6 @@ def dataframe(self): self._dataframe = df[[self.rescol, self.cencol]] return self._dataframe - @property - @np.deprecate - def filtered_data(self): - return self.dataframe - @property @np.deprecate def full_data(self): @@ -875,44 +866,6 @@ def verticalScatter(self, ax=None, pos=1, jitter=0.4, alpha=0.75, return fig - # other methods - @np.deprecate - def applyFilter(self, filterfxn, **fxnkwargs): - """ Filter the dataset and set the `include`/`exclude` - properties based on a user-defined function. - - Warning - ------- - This is very advanced functionality. Proceed with caution and - ask for help. - - Parameters - ---------- - filterfxn : callable - A user defined function that filters the data and determines - if the `include` attribute should be True or False. It *must* - return a pandas.DataFrame and a bool (in that order), or an - error will be raised. The `filterfxn` must accept the - `Location.data` attribute as its first argument. - - **fxnkwargs : keyword arguments - Optional named arguments pass to `filterfxn`. - - Returns - ------- - None - - """ - - newdata, include = filterfxn(self.full_data, **fxnkwargs) - if not isinstance(newdata, pandas.DataFrame): - raise ValueError ('first item returned by filterfxn must be a pandas.DataFrame') - - if not isinstance(include, bool): - raise ValueError ('second item returned by filterfxn must be a bool') - - self.include = include - class Dataset(object): """ Dataset: object for comparings two Location objects From ed0130813e32f6ddeca934bb078189f421580cbd Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 21 Oct 2015 18:22:34 -0700 Subject: [PATCH 5/8] don't cover the testutils --- wqio/testing/testutils.py | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/wqio/testing/testutils.py b/wqio/testing/testutils.py index 83d86c6d..bda05265 100644 --- a/wqio/testing/testutils.py +++ b/wqio/testing/testutils.py @@ -44,25 +44,11 @@ def assert_timestamp_equal(x, y): nptest.assert_equal(x.strftime('%x %X'), y.strftime('%x %X')) -def setup_prefix(folder): - for imgdir in ['baseline_images', 'result_images']: - subdir = os.path.join('.', imgdir) - subsubdir = os.path.join(subdir, folder) - - if not os.path.exists(subdir): - os.mkdir(subdir) - - if not os.path.exists(subsubdir): - os.mkdir(subsubdir) - - return subsubdir - - -def fail(message): +def fail(message): # pragma: no cover raise AssertionError(message) -def wip(f): +def wip(f): # pragma: no cover @wraps(f) def run_test(*args, **kwargs): try: @@ -74,7 +60,7 @@ def run_test(*args, **kwargs): return attr('wip')(run_test) -def compare_versions(utility='latex'): +def compare_versions(utility='latex'): # pragma: no cover "return True if a is greater than or equal to b" requirements = { 'latex': '3.1415' @@ -97,12 +83,12 @@ def compare_versions(utility='latex'): return False -def _show_package_info(package, name): +def _show_package_info(package, name): # pragma: no cover packagedir = os.path.dirname(package.__file__) print("%s version %s is installed in %s" % (name, package.__version__, packagedir)) -def _show_system_info(): +def _show_system_info(): # pragma: no cover import nose pyversion = sys.version.replace('\n','') @@ -125,7 +111,7 @@ def _show_system_info(): _show_package_info(pandas, 'pandas') -class NoseWrapper(nptest.Tester): +class NoseWrapper(nptest.Tester): # pragma: no cover ''' This is simply a monkey patch for numpy.testing.Tester. @@ -188,13 +174,13 @@ def ascii(s): return bytes(s, 'ascii') def byte2str(b): return b.decode('ascii') -else: +else: # pragma: no cover ascii = str def byte2str(b): return b -def checkdep_tex(): +def checkdep_tex(): # pragma: no cover try: s = subprocess.Popen(['tex','-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -207,7 +193,7 @@ def checkdep_tex(): return None -def assert_bigstring_equal(input_string, known_string, input_out, known_out): +def assert_bigstring_equal(input_string, known_string, input_out, known_out): # pragma: no cover try: nt.assert_equal(input_string, known_string) except: From 51f9822d2af389900cc550c320ad77f278d7f6c3 Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 21 Oct 2015 18:32:17 -0700 Subject: [PATCH 6/8] stop importing setup_prefix (it was deleted) --- wqio/tests/core_tests/features_tests.py | 1 - wqio/tests/core_tests/hydro_tests.py | 2 +- wqio/tests/core_tests/samples_tests.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/wqio/tests/core_tests/features_tests.py b/wqio/tests/core_tests/features_tests.py index d5d114ab..2fd0cddf 100644 --- a/wqio/tests/core_tests/features_tests.py +++ b/wqio/tests/core_tests/features_tests.py @@ -5,7 +5,6 @@ import numpy.testing as nptest from wqio import testing -from wqio.testing.testutils import setup_prefix usetex = testing.compare_versions(utility='latex') import matplotlib diff --git a/wqio/tests/core_tests/hydro_tests.py b/wqio/tests/core_tests/hydro_tests.py index ece24fa3..31536ff9 100644 --- a/wqio/tests/core_tests/hydro_tests.py +++ b/wqio/tests/core_tests/hydro_tests.py @@ -11,7 +11,7 @@ import pandas.util.testing as pdtest from wqio import testing -from wqio.testing.testutils import assert_timestamp_equal, setup_prefix +from wqio.testing.testutils import assert_timestamp_equal usetex = testing.compare_versions(utility='latex') import matplotlib diff --git a/wqio/tests/core_tests/samples_tests.py b/wqio/tests/core_tests/samples_tests.py index e9e6f5a5..dddaec22 100644 --- a/wqio/tests/core_tests/samples_tests.py +++ b/wqio/tests/core_tests/samples_tests.py @@ -11,7 +11,7 @@ import pandas.util.testing as pdtest from wqio import testing -from wqio.testing.testutils import assert_timestamp_equal, setup_prefix +from wqio.testing.testutils import assert_timestamp_equal usetex = testing.compare_versions(utility='latex') import matplotlib From 9e9b75829473a8c9d65d7174805917ea3413e272 Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 21 Oct 2015 18:39:55 -0700 Subject: [PATCH 7/8] don't cover old ROS module --- wqio/algo/ros.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wqio/algo/ros.py b/wqio/algo/ros.py index 8f720b9b..5267c548 100644 --- a/wqio/algo/ros.py +++ b/wqio/algo/ros.py @@ -15,7 +15,7 @@ @np.deprecate(message="algo.ros is deprectated. use algo.robustros instead.") -def rosSort(dataframe, rescol='res', qualcol='qual', ndsymbol='ND'): +def rosSort(dataframe, rescol='res', qualcol='qual', ndsymbol='ND'): # pragma: no cover """ Prepare a dataframe for ROS. It sorts ascending with non-detects on top. So something like this: [2, 4, 4, 10, 3, 5, 6, 10, 12, 40, 78, 120] @@ -53,7 +53,7 @@ def rosSort(dataframe, rescol='res', qualcol='qual', ndsymbol='ND'): return ros_data #.reset_index(drop=True) @np.deprecate(message="algo.ros is deprectated. use algo.robustros instead.") -class MR(object): +class MR(object): # pragma: no cover """ Censored data analysis via regression on order statistics (ROS) This class implements the MR method outlined Hirsch and Stedinger @@ -111,7 +111,7 @@ class MR(object): """ def __init__(self, data, rescol='res', qualcol='qual', finalcol='final_data', - ndsymbol='ND', fitlogs=True, dist='norm'): + ndsymbol='ND', fitlogs=True, dist='norm'): # pragma: no cover self.rescol = rescol self.qualcol = qualcol @@ -184,7 +184,7 @@ def _ros_DL_index(row): # select out only the necessary columns for data self.data = self.data[[self.finalcol, self.rescol, self.qualcol]] - def cohn(self): + def cohn(self): # pragma: no cover """ Creates a DataFrame of the unique detection limits in the dataset and the other Cohn numbers (A, B, C). """ @@ -269,7 +269,7 @@ def _C(row): return DLs - def _ros_ranks(self): + def _ros_ranks(self): # pragma: no cover """ Determine the ranks of the data according to the following logic: 1) rank[n] = rank[n-1] + 1 when: @@ -315,7 +315,7 @@ def avgrank(r): self.data['Avg Ranks'] = self.data.apply(avgrank, axis=1) - def estimator(self): + def estimator(self): # pragma: no cover """ Estimates the values of the censored data """ def _ros_plotting_pos(row): @@ -407,7 +407,7 @@ def _select_half_DLs(row): return self.data - def plot(self, filename): + def plot(self, filename): # pragma: no cover """ Makes a simple plot showing the original and modeled data Parameters From 43f501ff6df75741b2431877779121bc8d031544 Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 21 Oct 2015 18:44:54 -0700 Subject: [PATCH 8/8] add more exlude lines to coveragerc --- .travis_coveragerc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis_coveragerc b/.travis_coveragerc index 14da9dc9..11b114c6 100644 --- a/.travis_coveragerc +++ b/.travis_coveragerc @@ -16,11 +16,11 @@ omit = # Regexes for lines to exclude from consideration exclude_lines = - # Have to re-enable the standard pragma pragma: no cover - - # Don't complain if tests don't hit defensive assertion code: + def __repr__ + if self.debug: + if settings.DEBUG + raise AssertionError raise NotImplementedError - except NotImplementedError - # Ignore pass - pass + if 0: + if __name__ == .__main__.: