diff --git a/wqio/bootstrap.py b/wqio/bootstrap.py index a105f9b..cb9609e 100644 --- a/wqio/bootstrap.py +++ b/wqio/bootstrap.py @@ -13,7 +13,7 @@ "BootstrappedFitEstimate", ["xhat", "yhat", "lower", "upper", "xlog", "ylog"] ) -__all__ = ["BCA", "percentile"] +__all__ = ["BCA", "percentile", "fit"] def _acceleration(data): diff --git a/wqio/features.py b/wqio/features.py index a487734..d727d66 100644 --- a/wqio/features.py +++ b/wqio/features.py @@ -590,7 +590,7 @@ def probplot( ax.set_yticklabels([]) if rotateticklabels: - viz.rotateTickLabels(ax, 45, "x", ha="right") + viz.rotate_tick_labels(ax, 45, "x", ha="right") if bestfit: utils.fit_line() @@ -868,7 +868,7 @@ def exclude(self): def medianCIsOverlap(self): overlap = True if self.influent.hasData and self.effluent.hasData: - overlap = utils.checkIntervalOverlap( + overlap = utils.check_interval_overlap( self.influent.median_conf_interval, self.effluent.median_conf_interval, oneway=False, @@ -1302,7 +1302,7 @@ def probplot( ax.set_ylabel(ylabel) if rotateticklabels: - viz.rotateTickLabels(ax, 45, "x") + viz.rotate_tick_labels(ax, 45, "x") return fig @@ -1552,7 +1552,7 @@ def scatterplot( # include the line of equality, if requested if one2one: - viz.one2one( + viz.one2one_line( ax, linestyle="-", linewidth=1.25, @@ -1601,8 +1601,8 @@ def scatterplot( ax.annotate( r"$\log(y) = {} \, \log(x) + {}$".format( - utils.sigFigs(modelres.params[1], n=3), - utils.sigFigs(modelres.params[0], n=3), + utils.sig_figs(modelres.params[1], n=3), + utils.sig_figs(modelres.params[0], n=3), ), (txt_x, txt_y), xycoords="axes fraction", diff --git a/wqio/hydro.py b/wqio/hydro.py index 603b60f..1410840 100644 --- a/wqio/hydro.py +++ b/wqio/hydro.py @@ -197,7 +197,7 @@ def __init__( # tease out start/stop info self.start = self.data.index[0] self.end = self.data.index[-1] - self._season = utils.getSeason(self.start) + self._season = utils.get_season(self.start) # storm duration (hours) duration = self.end - self.start diff --git a/wqio/ros.py b/wqio/ros.py index 9ed53c7..7200d0a 100644 --- a/wqio/ros.py +++ b/wqio/ros.py @@ -582,7 +582,13 @@ def ROS( output = df[[result, censorship]].assign(final=df[result]) # normal ROS stuff - elif is_valid_to_ros(df, censorship, as_obj=False): + elif is_valid_to_ros( + df, + censorship, + max_fraction_censored=max_fraction_censored, + min_uncensored=min_uncensored, + as_obj=False, + ): output = _do_ros( df, result, diff --git a/wqio/samples.py b/wqio/samples.py index 790f81b..d7b07ad 100644 --- a/wqio/samples.py +++ b/wqio/samples.py @@ -103,7 +103,7 @@ def __init__( self._markersize = None self._linestyle = None self._yfactor = None - self._season = utils.getSeason(self.starttime) + self._season = utils.get_season(self.starttime) self.storm = storm @property diff --git a/wqio/tests/test_viz.py b/wqio/tests/test_viz.py index 575277b..a8efc47 100644 --- a/wqio/tests/test_viz.py +++ b/wqio/tests/test_viz.py @@ -605,7 +605,7 @@ def test_rotateTickLabels_xaxis(): fig, ax = pyplot.subplots() ax.set_xticks([1, 2, 3]) ax.set_xticklabels(["AAA", "BBB", "CCC"]) - viz.rotateTickLabels(ax, 60, "x") + viz.rotate_tick_labels(ax, 60, "x") return fig @@ -614,7 +614,7 @@ def test_rotateTickLabels_yaxis(): fig, ax = pyplot.subplots() ax.set_yticks([1, 2, 3]) ax.set_yticklabels(["AAA", "BBB", "CCC"]) - viz.rotateTickLabels(ax, -30, "y") + viz.rotate_tick_labels(ax, -30, "y") return fig @@ -626,7 +626,7 @@ def test_rotateTickLabels_both(): ax.set_yticks([1, 2, 3]) ax.set_yticklabels(["AAA", "BBB", "CCC"]) - viz.rotateTickLabels(ax, 45, "both") + viz.rotate_tick_labels(ax, 45, "both") return fig @@ -692,7 +692,7 @@ def test_one2one(): fig, ax = pyplot.subplots() ax.set_xlim([-2, 5]) ax.set_ylim([-3, 3]) - viz.one2one(ax, label="Equality", lw=5, ls="--") + viz.one2one_line(ax, label="Equality", lw=5, ls="--") ax.legend() return fig diff --git a/wqio/tests/utils_tests/test_dateutils.py b/wqio/tests/utils_tests/test_dateutils.py index fa1555a..1f670a8 100644 --- a/wqio/tests/utils_tests/test_dateutils.py +++ b/wqio/tests/utils_tests/test_dateutils.py @@ -1,11 +1,11 @@ -from datetime import datetime import warnings +from datetime import datetime -import pytest import pandas +import pytest -from wqio.utils import dateutils from wqio.tests import helpers +from wqio.utils import dateutils @pytest.mark.parametrize( @@ -22,7 +22,7 @@ ) def test_getSeason(datemaker, datestring, expected): date = datemaker(datestring) - season = dateutils.getSeason(date) + season = dateutils.get_season(date) assert season == expected @@ -45,13 +45,13 @@ def test_getSeason(datemaker, datestring, expected): def test_makeTimestamp_basic(row, expected, error): with warnings.catch_warnings(), helpers.raises(error): warnings.simplefilter("always") - tstamp = dateutils.makeTimestamp(row) + tstamp = dateutils.make_timestamp(row) assert tstamp == pandas.Timestamp(expected) def test_makeTimestamp_customcols(): row = {"mydate": "2012-05-25", "mytime": "16:54"} - tstamp = dateutils.makeTimestamp(row, datecol="mydate", timecol="mytime") + tstamp = dateutils.make_timestamp(row, datecol="mydate", timecol="mytime") assert tstamp == pandas.Timestamp("2012-05-25 16:54") @@ -59,7 +59,7 @@ def test_makeTimestamp_customcols(): "datemaker", [pandas.Timestamp, lambda x: datetime.strptime(x, "%Y-%m-%d")] ) @pytest.mark.parametrize("datestring", ["2005-10-02", "2006-09-02"]) -def test_getWaterYear(datemaker, datestring): +def test_get_wateryear(datemaker, datestring): date = datemaker(datestring) - wateryear = dateutils.getWaterYear(date) + wateryear = dateutils.get_wateryear(date) assert wateryear == "2005/2006" diff --git a/wqio/tests/utils_tests/test_numutils.py b/wqio/tests/utils_tests/test_numutils.py index 251c8d7..b7ae227 100644 --- a/wqio/tests/utils_tests/test_numutils.py +++ b/wqio/tests/utils_tests/test_numutils.py @@ -43,9 +43,9 @@ (numpy.inf * -1, 3, False, False, False, "NA", None), ], ) -def test_sigFigs(value, N, tex, forceint, pval, expected, error): +def test_sig_figs(value, N, tex, forceint, pval, expected, error): with helpers.raises(error): - result = numutils.sigFigs(value, N, tex=tex, forceint=forceint, pval=pval) + result = numutils.sig_figs(value, N, tex=tex, forceint=forceint, pval=pval) assert result == expected @@ -58,8 +58,8 @@ def test_sigFigs(value, N, tex, forceint, pval, expected, error): (0.00257, "=", 2, "=0.0026"), ], ) -def test_formatResult(num, qual, N, expected): - assert numutils.formatResult(num, qual, N) == expected +def test_format_result(num, qual, N, expected): + assert numutils.format_result(num, qual, N) == expected @pytest.mark.parametrize( @@ -143,7 +143,7 @@ def test_processAndersonDarlingResults(which): expected = {"bad": "<85.0%", "good": "99.0%"} - assert numutils.processAndersonDarlingResults(ARs[which]) == expected[which] + assert numutils.process_AD_result(ARs[which]) == expected[which] @pytest.mark.parametrize( @@ -287,7 +287,7 @@ def test_normalize_units_bad_conversion(units_norm_data): ) def test_test_pH2concentration(pH, expected, error): with helpers.raises(error): - assert abs(numutils.pH2concentration(pH) - expected) < 0.0001 + assert abs(numutils.pH_to_concentration(pH) - expected) < 0.0001 @helpers.seed @@ -501,9 +501,9 @@ def test_fit_line_with_xhat(fit_data): ) def test_checkIntervalOverlap_single(oneway, expected): result = [ - numutils.checkIntervalOverlap([1, 2], [3, 4], oneway=oneway), - numutils.checkIntervalOverlap([1, 4], [2, 3], oneway=oneway), - numutils.checkIntervalOverlap([1, 3], [2, 4], oneway=oneway), + numutils.check_interval_overlap([1, 2], [3, 4], oneway=oneway), + numutils.check_interval_overlap([1, 4], [2, 3], oneway=oneway), + numutils.check_interval_overlap([1, 3], [2, 4], oneway=oneway), ] assert result == expected @@ -513,7 +513,7 @@ def test_checkIntervalOverlap(oneway, expected): x = numpy.array([[1, 2], [1, 4], [1, 3]]) y = numpy.array([[3, 4], [2, 3], [2, 4]]) nptest.assert_array_equal( - numutils.checkIntervalOverlap(x, y, oneway=oneway, axis=1), + numutils.check_interval_overlap(x, y, oneway=oneway, axis=1), numpy.array(expected, dtype=bool), ) diff --git a/wqio/utils/dateutils.py b/wqio/utils/dateutils.py index 636473a..413f96e 100644 --- a/wqio/utils/dateutils.py +++ b/wqio/utils/dateutils.py @@ -9,7 +9,7 @@ _logger = logging.getLogger(__name__) -def getSeason(date): +def get_season(date): """Defines the season from a given date. Parameters @@ -50,7 +50,7 @@ def getSeason(date): return season -def makeTimestamp(row, datecol="sampledate", timecol="sampletime", issuewarnings=False): +def make_timestamp(row, datecol="sampledate", timecol="sampletime", issuewarnings=False): """Makes a pandas.Timestamp from separate date/time columns Parameters @@ -114,7 +114,7 @@ def makeTimestamp(row, datecol="sampledate", timecol="sampletime", issuewarnings return tstamp -def getWaterYear(date): +def get_wateryear(date): """Returns the water year of a given date Parameters @@ -132,7 +132,7 @@ def getWaterYear(date): >>> import datetime >>> import wqio >>> x = datetime.datetime(2005, 11, 2) - >>> print(wqio.utils.getWaterYear(x)) + >>> print(wqio.utils.get_wateryear(x)) 2005/2006 """ diff --git a/wqio/utils/numutils.py b/wqio/utils/numutils.py index 6f8df47..d6d3a89 100644 --- a/wqio/utils/numutils.py +++ b/wqio/utils/numutils.py @@ -13,7 +13,7 @@ TheilStats = namedtuple("TheilStats", ("slope", "intercept", "low_slope", "high_slope")) -def sigFigs(x, n, expthresh=5, tex=False, pval=False, forceint=False): +def sig_figs(x, n, expthresh=5, tex=False, pval=False, forceint=False): """Formats a number with the correct number of sig figs. Parameters @@ -41,10 +41,10 @@ def sigFigs(x, n, expthresh=5, tex=False, pval=False, forceint=False): Examples -------- - >>> print(sigFigs(1247.15, 3)) + >>> print(sig_figs(1247.15, 3)) 1,250 - >>> print(sigFigs(1247.15, 7)) + >>> print(sig_figs(1247.15, 7)) 1,247.150 """ @@ -54,7 +54,7 @@ def sigFigs(x, n, expthresh=5, tex=False, pval=False, forceint=False): # check on the number provided elif x is not None and not numpy.isinf(x) and not numpy.isnan(x): - # check on the sigFigs + # check on the sig_figs if n < 1: raise ValueError("number of sig figs must be greater than zero!") @@ -99,7 +99,7 @@ def sigFigs(x, n, expthresh=5, tex=False, pval=False, forceint=False): return out -def formatResult(result, qualifier, sigfigs=3): +def format_result(result, qualifier, sigfigs=3): """Formats a results with its qualifier Parameters @@ -118,12 +118,12 @@ def formatResult(result, qualifier, sigfigs=3): Example ------- - >>> formatResult(1.23, '<', sigfigs=4) + >>> format_result(1.23, '<', sigfigs=4) '<1.230' """ - return f"{qualifier}{sigFigs(result, sigfigs)}" + return f"{qualifier}{sig_figs(result, sigfigs)}" def process_p_vals(pval): @@ -145,7 +145,7 @@ def process_p_vals(pval): if pval is None: out = "NA" elif 0 < pval < 0.001: - out = formatResult(0.001, "<", sigfigs=1) + out = format_result(0.001, "<", sigfigs=1) elif pval > 1 or pval < 0: raise ValueError(f"p-values must be between 0 and 1 (not {pval})") else: @@ -220,7 +220,7 @@ def anderson_darling(data): return ADResult(**values) -def processAndersonDarlingResults(ad_results): +def process_AD_result(ad_result): """Return a nice string of Anderson-Darling test results Parameters @@ -235,7 +235,7 @@ def processAndersonDarlingResults(ad_results): """ - AD, crit, sig = ad_results + AD, crit, sig = ad_result try: ci = 100 - sig[crit < AD][-1] return f"{ci:0.1f}%" @@ -355,7 +355,7 @@ def normalize_units( return normalized -def pH2concentration(pH, *args): +def pH_to_concentration(pH, *args): """Converts pH values to proton concentrations in mg/L Parameters @@ -528,7 +528,7 @@ def fit_line(x, y, xhat=None, fitprobs=None, fitlogs=None, dist=None, through_or return xhat, yhat, results -def checkIntervalOverlap(interval1, interval2, oneway=False, axis=None): +def check_interval_overlap(interval1, interval2, oneway=False, axis=None): """Checks if two numeric intervals overlaps. Parameters @@ -560,7 +560,7 @@ def checkIntervalOverlap(interval1, interval2, oneway=False, axis=None): if oneway: return first_check else: - return first_check | checkIntervalOverlap(interval2, interval1, oneway=True, axis=axis) + return first_check | check_interval_overlap(interval2, interval1, oneway=True, axis=axis) def winsorize_dataframe(df, **limits): diff --git a/wqio/viz.py b/wqio/viz.py index d22ca8d..5dbc4e4 100644 --- a/wqio/viz.py +++ b/wqio/viz.py @@ -9,7 +9,7 @@ from wqio import utils, validate -def rotateTickLabels(ax, rotation, which, rotation_mode="anchor", ha="right"): +def rotate_tick_labels(ax, rotation, which, rotation_mode="anchor", ha="right"): """Rotates the ticklabels of a matplotlib Axes Parameters @@ -35,8 +35,8 @@ def rotateTickLabels(ax, rotation, which, rotation_mode="anchor", ha="right"): """ if which == "both": - rotateTickLabels(ax, rotation, "x", rotation_mode=rotation_mode, ha=ha) - rotateTickLabels(ax, rotation, "y", rotation_mode=rotation_mode, ha=ha) + rotate_tick_labels(ax, rotation, "x", rotation_mode=rotation_mode, ha=ha) + rotate_tick_labels(ax, rotation, "y", rotation_mode=rotation_mode, ha=ha) else: if which == "x": axis = ax.xaxis @@ -62,7 +62,7 @@ def _formatter(tick, pos=None, use_1x=True, threshold=3): else: tick = r"$10 ^ {%d}$" % int(numpy.log10(tick)) else: - tick = utils.sigFigs(tick, n=1) + tick = utils.sig_figs(tick, n=1) return str(tick) @@ -117,7 +117,7 @@ def gridlines(ax, xlabel=None, ylabel=None, xscale=None, yscale=None, xminor=Tru ax.yaxis.grid(True, which="minor", ls="-", alpha=0.17) -def one2one(ax, set_limits=True, set_aspect=True, **kwargs): +def one2one_line(ax, set_limits=True, set_aspect=True, **kwargs): label = kwargs.pop("label", "1:1 Line") axis_limits = [ numpy.min([ax.get_xlim(), ax.get_ylim()]),