Skip to content

pandas: get types of Interval correct - #167

Merged
Graham Wheeler (gramster) merged 9 commits into
microsoft:mainfrom
Dr-Irv:interval
Feb 23, 2022
Merged

Graham Wheeler (gramster) merged 9 commits into
microsoft:mainfrom
Dr-Irv:interval

Conversation

@Dr-Irv

@Dr-Irv Irv Lustig (Dr-Irv) commented Feb 18, 2022 •

Copy link
Copy Markdown
Contributor

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.

Comment thread partial/pandas/_libs/interval.pyi Outdated
@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
Copy Markdown
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.

Comment thread partial/pandas/_libs/interval.pyi Outdated
) -> Interval[int]: ...
@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
Copy Markdown
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
Graham Wheeler (gramster) merged commit 1e1b828 into microsoft:main Feb 23, 2022
@Dr-Irv
Irv Lustig (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

3 participants