Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## __NEXT__

### Bug fixes

* filter: Fix unhandled `ValueError` with `--group-by-weights` when no sequences pass earlier filters. [#2032] @victorlin

[#2032]: https://github.com/nextstrain/augur/issues/2032

## 34.1.0 (20 July 2026)

Expand Down
6 changes: 6 additions & 0 deletions augur/filter/subsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ def get_weighted_group_sizes(
) -> Dict[Group, int]:
"""Return target group sizes based on weights defined in ``weights_file``.
"""
if not records_per_group:
if output_sizes_file:
with open_file(output_sizes_file, "w", newline="") as f:
f.write("")
return {}
Comment thread
joverlee521 marked this conversation as resolved.

groups = records_per_group.keys()

weights = read_weights_file(weights_file)
Expand Down
16 changes: 16 additions & 0 deletions tests/filter/test_subsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,19 @@ def test_filter_groupby_only_year_month_provided(self, valid_metadata: pd.DataFr
'SEQ_4': ('B', '2020', '2020-01'),
'SEQ_5': ('B', '2020', '2020-01')
}


class TestWeightedGroupSizes:
def test_get_weighted_group_sizes_empty_records(self, tmp_path):
weights_file = tmp_path / "weights.tsv"
weights_file.write_text("country\tweight\nA\t1\n")

result = augur.filter.subsample.get_weighted_group_sizes(
records_per_group={},
group_by=['country', 'year'],
weights_file=str(weights_file),
target_total_size=10,
output_sizes_file=None,
random_seed=None,
)
assert result == {}
Loading