diff --git a/binomialbias/app.py b/binomialbias/app.py index 3993ac6..19dc273 100644 --- a/binomialbias/app.py +++ b/binomialbias/app.py @@ -220,7 +220,7 @@ def get_ui(): for key in ui_keys: try: raw = input[key]() - v = bbm.to_num(raw) + v = bbm.to_num(raw, die=False) u[key] = v except: print(f'Encountered error with input: {key} = "{raw}", continuing...') @@ -244,21 +244,22 @@ def reconcile_inputs(): for k in ui_keys: gv = g[k] uv = bbm.to_num(u[k]) - if k in slider_keys: - uv = round(uv) - match = sc.approx(gv, uv) - if not match: # Avoid floating point errors - print(f'Mismatch for {k}: {gv} ≠ {uv}') - g[k] = uv # Always set the current key to the current value - if k in ['nt', 'ntt']: - g.nt = uv - g.ntt = uv - reconcile_fracs('ne', 'na') - if k == 'ntt': - check_sliders() - else: - reconcile_fracs(k) - break + if not np.isnan(uv): + if k in slider_keys: + uv = round(uv) + match = sc.approx(gv, uv) + if not match: # Avoid floating point errors + print(f'Mismatch for {k}: {gv} ≠ {uv}') + g[k] = uv # Always set the current key to the current value + if k in ['nt', 'ntt']: + g.nt = uv + g.ntt = uv + reconcile_fracs('ne', 'na') + if k == 'ntt': + check_sliders() + else: + reconcile_fracs(k) + break # The isolation here avoids a potential infinite loop with sh.reactive.isolate(): diff --git a/binomialbias/main.py b/binomialbias/main.py index 38c7056..c8bfe74 100644 --- a/binomialbias/main.py +++ b/binomialbias/main.py @@ -25,14 +25,17 @@ def to_str(x, sf=3): return string -def to_num(x): +def to_num(x, die=False): """ Convert a string to a number, handling either ints or floats """ try: if sc.isnumber(x): x = to_str(x) num = float(x) if '.' in x else int(x) # Handle int or float - except: - num = np.nan + except Exception as E: + if die: + raise E + else: + num = np.nan return num @@ -352,7 +355,9 @@ def plot(self, dist_color='cornflowerblue', cdf_color='darkblue', ci_color='k', if gap or i == 1: ax.text(ira, dy+pmf[ira],'$n_a$', **textkw) - ax.set_aspect(d.n/vmax*0.3) + print('TEMP HI I AM', d.n, vmax, type(d.n), type(vmax), d.n/vmax*0.3) + + # ax.set_aspect(d.n/vmax*0.3) # Add frame labels if letters: