Skip to content

Commit 7091397

Browse files
committed
Fix evt sample seed handling bug
EVT sampling did not properly handle case where not integer seed is provided.
1 parent d17300e commit 7091397

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/seaflowpy/cli/commands/evt_cmd.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ def validate_positive(ctx, param, value):
2929

3030

3131
def validate_seed(ctx, param, value):
32-
if value is not None and (value < 0 or value > (2**32 - 1)):
33-
raise click.BadParameter('must be between 0 and 2**32 - 1.')
32+
if value is not None:
33+
try:
34+
value = int(value)
35+
except ValueError as e:
36+
raise click.BadParameter('must be an integer: {}.'.format(e))
37+
if (value < 0 or value > (2**32 - 1)):
38+
raise click.BadParameter('must be between 0 and 2**32 - 1.')
3439
return value
3540

3641

@@ -281,7 +286,7 @@ def beads_evt_cmd(cruise, cytograms, event_limit, frac, iqr, min_date,
281286
help='Apply noise filter before subsampling.')
282287
@click.option('-p', '--process-count', type=int, default=1, show_default=True, callback=validate_positive,
283288
help='Number of processes to use.')
284-
@click.option('-s', '--seed', type=int, callback=validate_seed,
289+
@click.option('-s', '--seed', callback=validate_seed,
285290
help='Integer seed for PRNG, otherwise system-dependent source of randomness is used to seed the PRNG.')
286291
@click.option('-S', '--sfl', 'sfl_path', type=click.Path(),
287292
help="""SFL file that can be used to associate dates with EVT files. Useful when

src/seaflowpy/sample.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def random_select(things, fraction, seed=None):
2828
list
2929
Chosen things.
3030
"""
31-
if not isinstance(seed, int):
32-
raise ValueError("seed must be an int")
31+
if (seed is not None) and not isinstance(seed, int):
32+
raise ValueError("seed must be an None or an int")
3333
if fraction < 0 or fraction > 1:
3434
raise ValueError("fraction must be between 0 and 1")
3535

@@ -286,8 +286,8 @@ def sample_one(df, n, noise_filter=True, min_chl=0, min_fsc=0, min_pe=0, seed=No
286286
"events_postsampling": event count after subsampling
287287
}
288288
"""
289-
if not isinstance(seed, int):
290-
raise ValueError("seed must be an int")
289+
if (seed is not None) and not isinstance(seed, int):
290+
raise ValueError("seed must be an None or an int")
291291
if n <= 0:
292292
raise ValueError("n must be > 0")
293293

0 commit comments

Comments
 (0)