Fix dataset filters matching datasets that never declare the filtered axis - #2587
Open
WatchTree-19 wants to merge 1 commit into
Open
Fix dataset filters matching datasets that never declare the filtered axis#2587WatchTree-19 wants to merge 1 commit into
WatchTree-19 wants to merge 1 commit into
Conversation
… axis
_match_single_criterion skips a field when the dataset's metadata for it is
None:
if filter_vals is None or meta_vals is None:
continue
meta_vals is None means the dataset never declared that axis, which is not the
same as declaring it and matching. Skipping drops the filtered axis entirely, so
the function returns True for every dataset that is simply silent about it.
That contradicts the method's own docstring - "Within each criterion, ALL
specified fields must match (AND across fields)" - and it contradicts
get_all_dataset_names_async seven lines earlier, which excludes datasets that
carry no metadata at all:
# Datasets without metadata are skipped for all other filters
if not metadata:
continue
So a dataset with partial metadata was treated as better qualified than one
with none.
It fires on both branches, because the skip happens before the strict_match
split, so strict_match=True is affected identically.
Scale: 839 of the 840 YAML dataset files under pyrit/datasets never declare
`modalities`, and every one of them currently satisfies a `modalities` filter.
Filtering on a harm category or a modality returns a set dominated by datasets
that say nothing about either, and nothing is logged.
get_all_dataset_names_async is the public discovery entry point and feeds
fetch_datasets_async, so this is a user asking for audio datasets and being
handed text ones.
Adds three tests: an undeclared axis does not match, the same under
strict_match, and an undeclared axis does not mask a declared mismatch when two
axes are filtered at once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
SeedDatasetProvider._match_single_criterionskips a field when the dataset's metadata for it isNone:meta_vals is Nonemeans the dataset never declared that axis, which is not the same as declaring it and matching. Skipping drops the filtered axis entirely, so the method returnsTruefor every dataset that is simply silent about it.Why this is a bug rather than a design choice
Two things in the file say so.
The docstring on this method (
Match a dataset's metadata against filter criteria):And
get_all_dataset_names_async, seven lines earlier, makes the opposite call for the neighbouring case:A dataset carrying no metadata is excluded. A dataset carrying partial metadata that is silent on the filtered axis is included. A dataset that says nothing at all is treated as less qualified than one that says nothing about the thing you asked for.
The skip also happens before the
strict_matchsplit, sostrict_match=Trueis affected identically — the stricter mode is no stricter here.Reproduction
Running the matcher verbatim against a dataset that declares
tags,sizeandsource_typebut is silent onmodalitiesandharm_categories:The second and fifth rows are controls: the check behaves correctly the moment the dataset declares the axis. This is purely the
Nonepath.Scale
839 of the 840 YAML dataset files under
pyrit/datasetsnever declaremodalities. Every one of them currently satisfies amodalitiesfilter. The same shape applies toharm_categories, which most locally-registered datasets also leave unset.get_all_dataset_names_asyncis the public discovery entry point and feedsfetch_datasets_async, so in practice this is a user filtering for audio datasets, or for one harm category, and being handed a set dominated by datasets that say nothing about either. Nothing is logged.The change
Separate the two
Nonecases. A filter that does not name an axis still skips it; a dataset that does not declare a named axis no longer matches it.Tests
Three added to
TestMetadataParsingRemote, all failing onmain:modalitiesandharm_categories, while a declared axis still matches normallystrict_match=TrueNothing in the existing suite locked in the old behaviour — the metadata-filter and strict-match tests all construct metadata that declares the axis under test.
What I did not verify
I did not run the full unit suite, only
tests/unit/datasets. I also have not confirmed whether "undeclared axis is a wildcard" was ever the intent; I argue against it from the docstring and from theif not metadata: continueprecedent, but if it was deliberate then the docstring and that neighbouring branch are the things that need changing instead, and I would rather be told.Written with AI assistance; I have read and can explain every line.