Skip to content

Conversation

@hyanwong
Copy link
Member

Fixes #784

Copy link
Member

@benjeffery benjeffery left a comment

Choose a reason for hiding this comment

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

So this doesn't break anything as the namedtuple supports indexing right? We'd need tests for the new left and right attributes though. Is there much of a perf hit?

@hyanwong
Copy link
Member Author

So this doesn't break anything as the namedtuple supports indexing right?

Yes

We'd need tests for the new left and right attributes though.

I've changed e.g. seek to use .right, and (I think) nexus uses both .left and .right, so I think the coverage stats will remain the same.

Is there much of a perf hit?

I would hope it would be negligible. But a browse around the internet implies accessing via name is a tad slower (damn), so we could switch to [0] and [1] within code that needs to be fast, I guess. I think the names are a big advantage, though, so this is still worth doing.

@jeromekelleher
Copy link
Member

I don't we need to worry about the perf hit if there is one, it's not going to matter.

We do want to explicitly test that we keep the old behaviour, though, and what the new behaviour is.

I don't think we should merge this until after 0.3.0, unless there's a good reason. We don't want to diverge to much from the betas and only put vital bugfixes in at this point.

@benjeffery
Copy link
Member

Yep, agreed on the merge freeze and explicit tests. Otherwise this is good.

@hyanwong
Copy link
Member Author

Explicit test added. Ready to merge after 0.3.0 released.

@jeromekelleher jeromekelleher added this to the Python 0.3.1 milestone Aug 21, 2020
@jeromekelleher
Copy link
Member

OK, tagged this with the 0.3.1 milestone so we know when to merge it.

@hyanwong
Copy link
Member Author

It might be nice (although certainly not vital) to add a .span property too:

BaseInterval = collections.namedtuple("BaseInterval", ["left", "right"])
class Interval(BaseInterval):
    @property
    def span(self):
        return self.right-self.left

Overkill?

@jeromekelleher
Copy link
Member

I don't see any harm, once it doesn't clash with the namedtuple behaviour.

Copy link
Member

@benjeffery benjeffery left a comment

Choose a reason for hiding this comment

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

Great, thanks for the extra tests. Happy to have span later as a separate PR.

@mergify mergify bot merged commit eda66fa into tskit-dev:master Aug 28, 2020
@hyanwong hyanwong deleted the interval-tuple branch September 11, 2020 13:10
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.

Create a namedtuple for interval values

3 participants