Skip to content

Conversation

@hyanwong
Copy link
Member

@hyanwong hyanwong commented Dec 1, 2025

Description

This has bugged me for ages: you can do ts.samples(population="AFR") without raising an error, although the population param is required to be an integer (so that snippet will always return an empty array)

I thought using int was the simplest way to check, as it avoids isinstance(population, string) or equivalent, and will deal with arrays etc, but it does allow ts.samples(population="0"), which maybe we don't want?

PR Checklist:

  • Tests that fully cover new/changed functionality.
  • Documentation including tutorial content if appropriate.
  • Changelogs, if there are API changes.

@hyanwong hyanwong force-pushed the fail-string-samples branch from aeede92 to 60a85a8 Compare December 1, 2025 10:02
@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.76%. Comparing base (f1b139e) to head (15fd849).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3344   +/-   ##
=======================================
  Coverage   89.76%   89.76%           
=======================================
  Files          29       29           
  Lines       31289    31292    +3     
  Branches     5737     5738    +1     
=======================================
+ Hits        28086    28089    +3     
  Misses       1794     1794           
  Partials     1409     1409           
Flag Coverage Δ
c-tests 86.77% <ø> (ø)
lwt-tests 80.38% <ø> (ø)
python-c-tests 87.12% <ø> (ø)
python-tests 98.85% <100.00%> (+<0.01%) ⬆️
python-tests-no-jit 33.51% <0.00%> (-0.02%) ⬇️
python-tests-numpy1 50.28% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
python/tskit/trees.py 98.89% <100.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs much more testing - just testing for one example when doing this type of type handling really isn't enough.

@hyanwong hyanwong force-pushed the fail-string-samples branch 3 times, most recently from a9f564a to 969032d Compare December 1, 2025 17:42
@hyanwong hyanwong force-pushed the fail-string-samples branch from c7e8a79 to 9ca7724 Compare December 2, 2025 13:49
Co-authored-by: Peter Ralph <petrel.harp@gmail.com>
@hyanwong hyanwong force-pushed the fail-string-samples branch from 9ca7724 to 15fd849 Compare December 2, 2025 13:59
@hyanwong
Copy link
Member Author

hyanwong commented Dec 2, 2025

Changes made and squashed.

We still don't have a good newbie solution for "get all the samples in the population named 'AFR'" though. At the moment I guess we recommend making a map, but that's not very beginner friendly:

name_to_id = {pop.metadata["name"]: pop.id for pop in ts.populations()}
ts.samples(name_to_id["AFR"])

See #1697 where I suggest ts.samples(population={'name':'EUR'})

@hyanwong hyanwong mentioned this pull request Dec 2, 2025
@hyanwong
Copy link
Member Author

hyanwong commented Dec 2, 2025

I'm waiting for this to merge so I can rebase #3345 . What's the etiquette here: if there is one approval, can the OP (me) click the merge button, or should I get someone else to do it? Do we require two approvals (I think not?)

@jeromekelleher jeromekelleher added this pull request to the merge queue Dec 3, 2025
Merged via the queue into tskit-dev:main with commit 6b6156c Dec 3, 2025
18 checks passed
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.

3 participants