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

TYP: timestamps.pyi #44339

Merged
merged 2 commits into from
Dec 19, 2021
Merged

TYP: timestamps.pyi #44339

merged 2 commits into from
Dec 19, 2021

Conversation

twoertwein
Copy link
Member

Should type annotations from a pyi files also be added to the pyx file (if possible)?

def combine(
cls, date: _date, time: _time, tzinfo: _tzinfo | None = ...
) -> datetime: ...
def combine(cls, date: _date, time: _time) -> datetime: ... # type: ignore[override]
Copy link
Member Author

Choose a reason for hiding this comment

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

the implementation does not accept tzinfo

fold: int = ...,
) -> datetime: ...
def astimezone(self: _S, tz: _tzinfo | None = ...) -> _S: ...
def ctime(self) -> str: ...
def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
# error: Signature of "isoformat" incompatible with supertype "datetime"
def isoformat(self, sep: str = ...) -> str: ... # type: ignore[override]
Copy link
Member Author

Choose a reason for hiding this comment

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

the implementation does not accept timespec

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm i thought we recently changed this

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that seems to have changed since Nov 6 :)

I will look through the other cases that don't match datetime and correct them if necessary in a new PR.

def __add__(self, other: np.ndarray) -> np.ndarray: ...
@overload
# TODO: other can also be Tick (but it cannot be resolved)
def __add__(self: _S, other: timedelta | np.timedelta64) -> _S: ...
Copy link
Member Author

Choose a reason for hiding this comment

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

once offset.pyi from #43744 is in a mergeable from, Tick can be added.

@@ -44,7 +44,7 @@ class Timestamp(datetime):
| _date
| datetime
| np.datetime64 = ...,
freq=...,
freq: int | None = ...,
Copy link
Member

Choose a reason for hiding this comment

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

i think freq can be a DateOffset?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I will add that.

One question: DateOffset is used in a few places, but I think no class inherits from it. There is even this case:

cdef class RelativeDeltaOffset(BaseOffset):
    """
    DateOffset subclass backed by a dateutil relativedelta object. [...]
    """

Is DateOffset still being used or should most of its uses be replaced with BaseOffset?

Copy link
Member

Choose a reason for hiding this comment

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

you're right, i think BaseOffset is technically correct. its annoying that DateOffset is a more informative name

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Nov 8, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2021

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

comment but let's merge

fold: int = ...,
) -> datetime: ...
def astimezone(self: _S, tz: _tzinfo | None = ...) -> _S: ...
def ctime(self) -> str: ...
def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
# error: Signature of "isoformat" incompatible with supertype "datetime"
def isoformat(self, sep: str = ...) -> str: ... # type: ignore[override]
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm i thought we recently changed this

@jreback jreback merged commit 325ce29 into pandas-dev:master Dec 19, 2021
@jreback
Copy link
Contributor

jreback commented Dec 19, 2021

maybe worth it to use something more descriptive than _S for the type var

@jbrockmendel
Copy link
Member

maybe worth it to use something more descriptive than _S for the type var

IIRC thats what they used in the microsoft stubs that i based this on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants