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

pandas: get types of Interval correct #167

Merged
merged 9 commits into from
Feb 23, 2022
Merged

Conversation

Dr-Irv
Copy link
Contributor

@Dr-Irv Dr-Irv commented Feb 18, 2022

Interval.length is a property that is overloaded, and has a result dependent on the constructor, but you can't do that, so this fixes that issue.

Also updated Timestamp and Timedelta by taking them from the pandas distribution to fix other issues.

@property
@overload
def left(self: Interval[Orderable]) -> Orderable: ...
def left(self: Interval[OrderableT]) -> Orderable: ...

Choose a reason for hiding this comment

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

Are all the overloads needed for left/right? I think this might be enough:

def left(self: Interval[OrderableT]) -> OrderableT: ...
def right(self: Interval[OrderableT]) -> OrderableT: ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are all the overloads needed for left/right? I think this might be enough:

def left(self: Interval[OrderableT]) -> OrderableT: ...
def right(self: Interval[OrderableT]) -> OrderableT: ...

Yes, that is correct. Changed in next commit.

@overload
def length(self: Interval[Orderable]) -> Orderable: ...
def __new__(

Choose a reason for hiding this comment

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

and the same for __new__

    def __new__(
        cls,
        left: OrderableT,
        right: OrderableT,
        closed: Literal["left", "right", "both", "neither"] = ...,
    ) -> Interval[OrderableT]: ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of them are needed. That's how you end up with the specific matching of input types to the proper Interval[] subtype. I tried removing them and then length has the wrong type.

@gramster gramster merged commit 1e1b828 into microsoft:main Feb 23, 2022
@Dr-Irv Dr-Irv deleted the interval branch February 23, 2022 22:34
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