Skip to content

Fixes issue #8 - #185

Merged
jeromekelleher merged 2 commits into
tskit-dev:masterfrom
hyanwong:allow_compatible_array_types
May 28, 2019
Merged

jeromekelleher merged 2 commits into
tskit-dev:masterfrom
hyanwong:allow_compatible_array_types

Conversation

@hyanwong

Copy link
Copy Markdown
Member

Solving #8 seems a bit more convoluted than I had expected, but we need to allow passing [], which by default is of dtype np.float64, and it seems as if numpy doesn't have any built-in bounds checking. I've created a function to_np_int32 as I imagine we might want to use this in other python functions, as per the set_columns example by @petrelharp. But perhaps there's a neater solution.

As a bonus, this now catches errors like ts.simplify([0.1,1.3]) which used to convert silently to ints, and it also returns a TypeError for ts.simplify({}) rather than ValueError, which seems more correct to me. I've also added a few more test cases.

@codecov

codecov Bot commented May 22, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #185 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #185      +/-   ##
==========================================
+ Coverage   85.95%   85.97%   +0.01%     
==========================================
  Files          16       16              
  Lines        8732     8744      +12     
  Branches     1678     1680       +2     
==========================================
+ Hits         7506     7518      +12     
  Misses        733      733              
  Partials      493      493
Flag Coverage Δ
#c_tests 85.97% <100%> (+0.01%) ⬆️
#python_tests 98.28% <100%> (ø) ⬆️
Impacted Files Coverage Δ
python/tskit/tables.py 99.79% <100%> (ø) ⬆️

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 6c536e8...8857835. Read the comment docs.

@jeromekelleher jeromekelleher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like this something like this is the only option. We'd need some specific tests on the as_int32 function though.

Comment thread python/tskit/tables.py Resolved
@hyanwong
hyanwong force-pushed the allow_compatible_array_types branch from dcdd591 to 1fac82a Compare May 23, 2019 20:28
@hyanwong

Copy link
Copy Markdown
Member Author

Is the right place to put my to_np_int32() function at the end of the tables.py file, and is the name OK?

Re: tests. These are done somewhat in the test_samples_interface() code, but I guess it would be useful to have a standalone set too.

@hyanwong
hyanwong force-pushed the allow_compatible_array_types branch from 1fac82a to 6b83479 Compare May 23, 2019 21:36
Comment thread python/tests/test_tables.py Resolved
Comment thread python/tskit/tables.py Resolved
@jeromekelleher

Copy link
Copy Markdown
Member

Is the right place to put my to_np_int32() function at the end of the tables.py file, and is the name OK?

Sure, this is as good a place as any and name is good.

@hyanwong
hyanwong force-pushed the allow_compatible_array_types branch from 6b83479 to 87adaf4 Compare May 24, 2019 09:08
@hyanwong

Copy link
Copy Markdown
Member Author

I could also use to_np_int32() in tables.nodes.set_columns for the flags param, as flagged up by @petrelharp , but presumably there are a good number of places where we might want to apply this function, and I'm not the best placed to know where they all are, or how to compile a sensible list.

@jeromekelleher

Copy link
Copy Markdown
Member

Flags is uint32, so we'd need a slightly different version there. I think the to_int32 should be applied anywhere we referring to object IDs. These will be in the Tables API (node IDs, site IDs, etc), and where we compute stats (GNN, eg, takes lists of samples). We don't have to do it all at once, but it would be good to follow up with an issue saying this needs to be done if you don't want to do it here.

@hyanwong

Copy link
Copy Markdown
Member Author

We don't have to do it all at once, but it would be good to follow up with an issue saying this needs to be done if you don't want to do it here.

Right. I'll open an issue once this is merged.

Comment thread python/tskit/tables.py Resolved
@jeromekelleher
jeromekelleher force-pushed the allow_compatible_array_types branch from 062348c to 8857835 Compare May 28, 2019 13:44
@jeromekelleher

Copy link
Copy Markdown
Member

Merging, thanks @hyanwong.

@jeromekelleher
jeromekelleher merged commit 0aa01b3 into tskit-dev:master May 28, 2019
@hyanwong
hyanwong deleted the allow_compatible_array_types branch May 28, 2019 20:36
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