From 19bd80e7194bc948b41a7a3cb4e678bf3c640f80 Mon Sep 17 00:00:00 2001 From: Cliff Kerr Date: Fri, 15 Sep 2023 10:39:04 -0400 Subject: [PATCH] add plot_bias test --- binomialbias/main.py | 19 ++++++++++++++----- tests/test_plotting.py | 14 +++++++++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/binomialbias/main.py b/binomialbias/main.py index 2a56a5a..57b6ea2 100644 --- a/binomialbias/main.py +++ b/binomialbias/main.py @@ -78,8 +78,8 @@ def __init__(self, n=20, n_e=10, n_a=7, f_e=None, f_a=None, one_sided=True, B.display() """ # Handle deprecations - expected = kwargs.pop('expected', n_e) - actual = kwargs.pop('actual', n_a) + expected = kwargs.pop('expected', None) or n_e + actual = kwargs.pop('actual', None) or n_a if 0 < expected < 1: f_e = expected # Treat as fractions if 0 < actual < 1: f_a = actual @@ -372,9 +372,18 @@ def plot(self, dist_color='cornflowerblue', cdf_color='darkblue', ci_color='k', return fig -def plot_bias(n=20, expected=10, actual=7, show=True, letters=True, display=True, **kwargs): - """ Script to simply plot the bias without creating a class instance; see BinomialBias for arguments """ - B = BinomialBias(n=n, expected=expected, actual=actual) +def plot_bias(show=True, letters=True, display=True, **kwargs): + """ + Script to simply plot the bias without creating a class instance; see BinomialBias for arguments + + **Example**:: + + import binomialbias as bb + bb.plot_bias(n=20, n_e=10, n_a=7) + """ + bb_keys = ['n', 'n_e', 'n_a', 'f_e', 'f_a', 'expected', 'actual'] + bb_kwargs = {k:kwargs.pop(k) for k in bb_keys if k in kwargs} + B = BinomialBias(**bb_kwargs) B.plot(show=show, letters=letters, **kwargs) if display: B.display() diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 561de29..fa6e000 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -1,13 +1,13 @@ -''' +""" Simple tests of plotting -''' +""" import sciris as sc import binomialbias as bb def test_plotting(show=False): - ''' Test several different plotting options ''' + """ Test several different plotting options """ sc.options(interactive=show) @@ -25,7 +25,15 @@ def test_plotting(show=False): return out +def test_plot_bias(show=False): + """ Test function example """ + sc.options(interactive=show) + B = bb.plot_bias(n=20, n_e=10, n_a=7, show=show) + return B + + if __name__ == '__main__': out = test_plotting(show=True) + B = test_plot_bias(show=True) \ No newline at end of file