Skip to content

Refuse loader inputs that are read silently or refused without naming the argument — Closes #23 - #26

Draft
conradbzura wants to merge 7 commits into
mainfrom
23-refuse-unhonoured-loader-inputs
Draft

conradbzura wants to merge 7 commits into
mainfrom
23-refuse-unhonoured-loader-inputs

Conversation

@conradbzura

@conradbzura conradbzura commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Six inputs on the training path were either accepted though they could not be honoured, or refused in words that named neither the argument nor the file. This PR moves each refusal to the layer where the input is first given and words it in quadrat's terms.

Input Before After
A window cache over a different number of windows than the dataset's frames Read another window's signal on every draw (more windows), or failed at the first read past the end (fewer) LocusDataset raises ValueError naming the cache and both counts
True or 2.0 as a count, seed, epoch, batch size, window width or worker count Read as 1, or truncated to 2 TypeError naming the argument
A missing reference FileNotFoundError from load_windows, pyfaidx's FastaNotFoundError from the extractors, an engine error from chrom_lengths FileNotFoundError, in the same words, from every entry point
A bigWig or other non-Parquet file given as a track Passed require_complete and failed later in polars' words, naming no file ValueError naming the path, from every reader that opens it
extract_loci(signals=[]) Answered zero-channel tensors, so the default target_idx named no track and raised nothing ValueError, saying to pass None
Exclusion([Exclusion(...), "b.bed"]) Passed construction and failed when the regions were read Refused at construction, with the top-level message

The one remaining hole is documented: a cache built over different windows of the same count passes, because no count can tell it apart.

Closes #23

Proposed changes

Window count (quadrat.cache, quadrat.dataset)

WindowSignalCache gains a public n_windows, answered from the counts array_meta already records, so nothing is mapped to read it. LocusDataset.__init__ refuses a signal or control cache whose n_windows is not the two frames' rows combined, beside the check it already makes of a sampler's size. A cache constructed directly with no record is counted from its arrays. n_windows becomes part of the reader protocol signal_cache and control_cache document. A missing signal_cache is refused by name, and the two caches and the two widths become read-only attributes, so nothing checked at construction can be bypassed by assigning another.

One integer rule (quadrat._engine, quadrat.rules, quadrat.sampling, quadrat.loader, quadrat.loci, quadrat.dataset)

quadrat._engine.require_integer(label, value) holds the rule require_index used inline: any numbers.Integral, numpy's included, except a bool. It sits in the lowest layer so every module can share it. require_index, which now always takes a row count, and the Jitter, Exclusion and Aggregate field checks now call it, and so do:

  • PeakNegativeMixSampler: n_peaks, n_negatives, random_state, set_epoch and plan, and n_negatives in validate_arguments, which now answers the normalised count.
  • ShardedEpochSampler: n, set_epoch, and batch_size, rank and world_size in validate_arguments. That method now raises TypeError as well, and answers the normalised values.
  • RechunkedLoader: batch_size, and the wrapped loader's batch_size.
  • auto_fetch_size: every argument, with prefetch_factor=None still taken as torch's default, as a loader without workers holds it.
  • build_training_loader: in_window, out_window, num_workers, max_fetch_bytes, fetch_size and random_state, all refused before anything is read.
  • load_windows and LocusDataset: the two window widths.

A plain int is answered before the ABC test, so the check costs nothing measurable on the per-draw epoch path. A float is refused where int(...) used to truncate it, so a float fetch_size is now a TypeError where it was a ValueError. as_jitter and validate_signal_groups keep their own checks, which already refuse bool, because their messages name what the shared one cannot: the Jitter alternative, and the whole group specification.

Missing reference (quadrat.reference, quadrat.loci, quadrat.stores)

reference.require_reference(path) raises FileNotFoundError("<path> is not a reference; …"). Two readers call it before they open the file:

  • chrom_lengths, so load_windows drops its own inline copy of the check.
  • SequenceStore, so extract_sequences and extract_loci raise the same error.

A path running through a file counts as missing too. A path that cannot be examined, e.g. inside a directory that cannot be searched, raises OSError, and a reference that exists but cannot be opened still raises pyfaidx's error, which is an OSError and names the path. chrom_lengths is where the published reference states all of this; pileup_alignments, pileup_many and every other reader point there.

A track that is no track (quadrat.tables, quadrat.stores)

tables.track_signal, the one verifier of a track behind require_complete, now reads the four bytes every Parquet file begins with (PAR1). A single file without them is refused with a ValueError naming the path and saying what a track is. The check reads the file's content rather than its suffix, because a single-file table need carry no suffix, which is why the port dropped upstream's suffix test.

require_complete and TrackStore reach the check through track_signal, and track_frame and track_contigs now consult it for a single file as they already did for a directory. A directory neither named as a track nor holding any Parquet, a folder of bigWigs say, is refused in the same words rather than told to pile up again. Each entry point's refusal of a missing track is unchanged, and the readers now document the OSError an unreadable file raises.

Empty track lists (quadrat.loci)

extract_loci refuses an empty signals or controls list. Zero channels mean nothing to either, and None is how a caller asks for none. extract_signal(windows, []) is unchanged: it is a plain reader, and a zero-channel answer is consistent there.

Nested Exclusion (quadrat.rules)

Exclusion.__post_init__ refuses an Exclusion anywhere in a list or tuple of regions with the message it gives at the top level.

Test cases

# Test Suite Given When Then Coverage Target
1 test_cache True, a numpy bool, 1.0, "1" Each is required as an index Raises TypeError naming the label Shared integer rule
2 test_cache Any non-negative Python integer, or numpy int64 or int32 (Hypothesis) Each is required as an index of more rows Answers it equal, as a plain int Accepted integers
3 TestWindowSignalCache Caches over 0, 1 and 3 windows, in memory, mapped and adopted, and one constructed with no record n_windows is read Equals the window count New property
4 TestLocusDataset A signal cache over one window more or fewer than the frames The dataset is constructed Raises ValueError naming signal_cache and both counts Signal count check
5 TestLocusDataset A matching signal cache and a control cache over one window more The dataset is constructed Raises ValueError naming control_cache Control count check
6 TestLocusDataset A built dataset Another cache, or a bool width, is assigned to signal_cache, control_cache, in_window or out_window Raises AttributeError Checked attributes fixed at construction
6a TestLocusDataset None as the signal cache The dataset is constructed Raises ValueError naming signal_cache Missing signal reader
7 TestLocusDataset True as in_window or out_window The dataset is constructed Raises TypeError naming the width Dataset widths
8 TestPeakNegativeMixSampler True or 2.0 as n_peaks, n_negatives or random_state The sampler is constructed Raises TypeError naming the argument Constructor integers
9 TestPeakNegativeMixSampler Numpy integer counts, seed and epoch The sampler plans that epoch Holds int counts and plans what plain integers plan Numpy integers accepted
10 TestPeakNegativeMixSampler True or 1.0 as the epoch, or epoch True to plan set_epoch or plan is called Raises TypeError naming epoch, leaving the epoch at zero Epoch integers
11 TestShardedEpochSampler True or 2.0 as batch_size, rank or world_size validate_arguments is called Raises TypeError naming it Validation by type
12 TestShardedEpochSampler, TestPeakNegativeMixSampler Numpy integers given to validate_arguments, or True or 2.0 as n_negatives validate_arguments is called Answers them as plain int, or raises TypeError naming n_negatives Validators refuse and normalise
13 TestShardedEpochSampler True or 4.0 as n, or epoch True, or numpy integers for every argument The sampler is constructed, or set_epoch is called Raises TypeError naming the argument, or holds each as a plain int n, set_epoch and normalisation
14 TestRechunkedLoader True or 4.0 as the batch, a wrapped loader whose batch_size is True, or numpy integers for both The loader is wrapped Raises TypeError naming which batch_size, or holds both as plain int Consumer batch and fetch
15 test_loader True or a float as any of fetch_size, batch_size, rank, world_size, random_state, in_window, out_window, num_workers or max_fetch_bytes, among missing files build_training_loader is called Raises TypeError before anything is read or keyed Loader integers refused early
16 test_loader True as any argument, a loader's own prefetch_factor, or prefetch_factor=None on an epoch whose fetch depends on the depth auto_fetch_size is called Raises TypeError naming it, or answers what a depth of 2 answers and not what 1 does Fetch-size integers
17 test_loci True or a float as a window width load_windows is called Raises TypeError naming the width Window widths
18 test_reference, test_track, test_run, test_loader A path with no file, the loader both keyed and unkeyed chrom_lengths, pileup_alignments, pileup_many or build_training_loader is called Raises FileNotFoundError saying it is not a reference, with no scan warning and no cache entry Every documented entry
19 test_reference A missing path, a path running through a file, an existing file, and a reference in a directory that cannot be searched require_reference or chrom_lengths is called Raises FileNotFoundError for the first two, passes the third, and raises an OSError that is not FileNotFoundError for the last The missing-or-unexaminable split
20 TestSequenceStore A missing reference A window or the contig lengths are read Raises FileNotFoundError saying it is not a reference Store entries
21 test_loci A missing reference extract_sequences or extract_loci is called Raises FileNotFoundError saying it is not a reference Extract entries
22 test_tables A bigWig-like file or an empty file, or a directory holding only a bigWig require_complete or track_contigs is called Raises ValueError naming the path and saying what a track is Content test at the verifier
22a test_tables A directory of Parquet with no record under another name, one that cannot be listed, or a track directory named with a trailing separator require_complete or track_signal is called Raises ValueError saying it cannot be verified complete, not that it is no track Interrupted writes keep their message
23 test_tables A Parquet track under a name with no suffix, or under .parquet require_complete is called Returns the path No false refusal
24 test_stores, test_loci, test_loader A bigWig-like file or an empty file track_frame, extract_loci or build_training_loader is called Raises ValueError naming the path, extract_loci before indexing the reference Content test where users meet it
25 TestTrackStore A channel set holding a non-Parquet file, or a missing path The store is built Raises ValueError naming the path Refusal at construction
26 TestTrackStore A single-file Parquet track The store is built and a window read Answers the stored value Real single file passes
27 test_loci An empty list as signals or as controls extract_loci is called Raises ValueError saying to pass None Empty track list
28 TestExclusion A list or tuple of regions holding an Exclusion, or an Exclusion as the regions An Exclusion is constructed over them Raises TypeError with one message telling the caller to pass the rules side by side Nested refusal

@conradbzura conradbzura self-assigned this Nov 18, 2026
@conradbzura
conradbzura force-pushed the 23-refuse-unhonoured-loader-inputs branch 3 times, most recently from fb3881c to ca52bce Compare November 19, 2026 19:54
The integer rule, any numbers.Integral but a bool, was written inline
in require_index and again in the Jitter, Exclusion and Aggregate field
checks. It now lives once in quadrat._engine, the lowest layer, so
require_index, those fields, and the sampler and loader arguments that
follow all refuse the same values in the same words.

A plain int is answered before the ABC test, which costs several times
the call on the per-draw epoch path; bool is a subclass and fails it.

as_jitter and validate_signal_groups keep their own checks, whose
messages name what require_integer cannot: the Jitter alternative, and
the whole group specification.
PeakNegativeMixSampler(True, True) built a sampler over one peak and
one negative, set_epoch(True) set epoch 1, RechunkedLoader read True as
a batch of one, and in_window=True built one-base windows, because each
normalised through int() or not at all, which admits a bool and
truncates a float.

Every integer argument of both samplers and their validate_arguments,
RechunkedLoader, auto_fetch_size and build_training_loader, and the
window widths load_windows and LocusDataset take, now goes through
require_integer and raises TypeError naming the argument.
build_training_loader makes these refusals before anything is read; a
float fetch_size is now a TypeError where it was a ValueError. Both
validate_arguments answer the values they normalised, and
auto_fetch_size still takes the prefetch_factor of None a loader
without workers holds.

require_index now always takes the row count; the one caller that used
it as a bare integer check, the dataset's epoch, calls require_integer.
LocusDataset bounded a draw by its two window frames and never by the
cache it reads, so a cache over more windows answered another window's
signal for every draw, and one over fewer failed only at the first read
past its end. WindowSignalCache now answers n_windows from the counts
array_meta recorded, or counts its arrays where it has none, and the
dataset refuses a missing signal cache, and a signal or control cache
whose count is not the frames' rows combined, as it already refuses a
sampler of the wrong size. The caches and widths are read-only
attributes, so nothing checked at construction can be bypassed by
assigning another.

A cache over other windows of the same count still passes; no count
can tell it apart.
load_windows raised FileNotFoundError for a missing reference, while
SequenceStore, and so extract_sequences and extract_loci, raised
pyfaidx's FastaNotFoundError, and chrom_lengths fell through to a scan
that failed in the engine's words. Both types are OSError, but a
caller handling one missed the other.

The refusal now lives in reference.require_reference, which
chrom_lengths and SequenceStore call before opening the file, so every
entry point, the pileups included, raises FileNotFoundError in the same
words. A path running through a file counts as missing; one that
cannot be examined raises OSError, and a reference that exists but
cannot be opened still raises pyfaidx's error. chrom_lengths is where
the published docs state this, and every other reader points there.
A bigWig or any other file given as a track passed require_complete,
track_frame, track_contigs and TrackStore, and failed later in polars'
words, naming no file. The port had dropped upstream's suffix test on
purpose, since a single-file table need carry no suffix. track_signal,
the one verifier of a track, now reads the four bytes every Parquet
file begins with and refuses a file without them with a ValueError
naming the path and saying what a track is; track_frame and
track_contigs consult it for a single file as for a directory. A
directory neither named as a track nor holding any Parquet is refused
in the same words, rather than told to pile up again.

Each entry point's refusal of a missing track is unchanged.
extract_loci(signals=[]) answered zero-channel signal tensors, and its
default target_idx of 0 then named no track without raising. An empty
signals or controls list is now refused with a ValueError saying to
pass None to read none; zero channels mean nothing to either.
Exclusion(Exclusion(...)) was refused with a message saying to list
both, but Exclusion([Exclusion(...), "b.bed"]) passed construction and
failed later when the regions were read. An Exclusion anywhere in a
list or tuple of regions now gets the top-level refusal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refuse loader inputs that are read silently or refused without naming the argument

1 participant