Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load_text only creates populations if none given #1910

Merged
merged 1 commit into from Nov 12, 2021

Conversation

hyanwong
Copy link
Member

@hyanwong hyanwong commented Nov 12, 2021

Fixes #1909

PR Checklist:

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

@jeromekelleher
Copy link
Member

jeromekelleher commented Nov 12, 2021

Looks good. It would be nice to add a couple of minimal tests like (paraphrased)

def test_parse_text_no_populations(self):
    nodes = """\
       is_sample  time  population
        1                0      2
     """
     tables = parse_text(nodes)
     assert len(tables.nodes) == 1
     assert len(tables.populations) == 3

def test_parse_text_populations(self):
       populations = """\
       metadata
       metadata1
       metadata2
       """
       tables = parse_text(populations)     
       assert len(tables.populations) == 2
       assert tables.popualtions[0].metadata == "metadata1"
       assert tables.popualtions[0].metadata == "metadata2"

This will exercise both paths. I'm becoming a big fan of small obvious tests, they're so much more effective than the big elaborate code-based approaches that I used to favour.

@codecov
Copy link

codecov bot commented Nov 12, 2021

Codecov Report

Merging #1910 (7f62573) into main (d467e0b) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1910   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          27       27           
  Lines       25094    25094           
  Branches     1109     1109           
=======================================
  Hits        23379    23379           
  Misses       1681     1681           
  Partials       34       34           
Flag Coverage Δ
c-tests 92.21% <ø> (ø)
lwt-tests 89.14% <ø> (ø)
python-c-tests 68.29% <50.00%> (ø)
python-tests 98.78% <100.00%> (ø)

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

Impacted Files Coverage Δ
python/tskit/trees.py 97.79% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d467e0b...7f62573. Read the comment docs.

@hyanwong
Copy link
Member Author

hyanwong commented Nov 12, 2021

Looks good. It would be nice to add a couple of minimal tests...

Good call. This exposed another bug: we were forgetting to strip the "\n" from each line when doing strict text reading. I've added this in, but apart from the test you suggested above, which only applied to the population table, this change doesn't have an associated unit test.

(I've also changed the strip("\n") to rstrip("\n") which is a bit more specific)

@hyanwong hyanwong force-pushed the load_text-fix branch 2 times, most recently from daa0cf7 to 857649f Compare November 12, 2021 15:32
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.

LGTM

@jeromekelleher jeromekelleher added the AUTOMERGE-REQUESTED Ask Mergify to merge this PR label Nov 12, 2021
@mergify mergify bot merged commit 6a803c6 into tskit-dev:main Nov 12, 2021
@mergify mergify bot removed the AUTOMERGE-REQUESTED Ask Mergify to merge this PR label Nov 12, 2021
@hyanwong hyanwong deleted the load_text-fix branch November 12, 2021 18:43
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.

tskit.load_text creates an extra population
3 participants