Skip to content

TYP: remove NaTType as possible result of Timestamp and Timedelta constructor #46171

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

Merged
merged 20 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pandas/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ class Timedelta(timedelta):
max: ClassVar[Timedelta]
resolution: ClassVar[Timedelta]
value: int # np.int64

# error: "__new__" must return a class instance (got "Union[Timedelta, NaTType]")
def __new__( # type: ignore[misc]
def __new__(
cls: Type[_S],
value=...,
unit: str = ...,
**kwargs: int | float | np.integer | np.floating,
) -> _S | NaTType: ...
) -> _S: ...
@property
def days(self) -> int: ...
@property
Expand Down
6 changes: 2 additions & 4 deletions pandas/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class Timestamp(datetime):

resolution: ClassVar[Timedelta]
value: int # np.int64

# error: "__new__" must return a class instance (got "Union[Timestamp, NaTType]")
def __new__( # type: ignore[misc]
def __new__(
cls: type[_DatetimeT],
ts_input: int
| np.integer
Expand All @@ -56,7 +54,7 @@ class Timestamp(datetime):
tzinfo: _tzinfo | None = ...,
*,
fold: int | None = ...,
) -> _DatetimeT | NaTType: ...
) -> _DatetimeT: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment (maybe ref this issue) about the reasoning here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in next commit

def _set_freq(self, freq: BaseOffset | None) -> None: ...
@property
def year(self) -> int: ...
Expand Down