-
-
Notifications
You must be signed in to change notification settings - Fork 145
Timestamp -> datetime and Timedelta -> timedelta #841
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ from datetime import ( | |
timedelta, | ||
tzinfo as _tzinfo, | ||
) | ||
import sys | ||
from time import struct_time | ||
from typing import ( | ||
ClassVar, | ||
|
@@ -100,16 +99,8 @@ class Timestamp(datetime): | |
def tz(self) -> _tzinfo | None: ... | ||
@property | ||
def fold(self) -> int: ... | ||
|
||
if sys.version_info < (3, 12): | ||
@classmethod | ||
def fromtimestamp(cls, t: float, tz: _tzinfo | str | None = ...) -> Self: ... | ||
else: | ||
@classmethod | ||
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride] | ||
cls, t: float, tz: _tzinfo | str | None = ... | ||
) -> Self: ... | ||
|
||
@classmethod | ||
def fromtimestamp(cls, t: float, tz: _tzinfo | str | None = ...) -> Self: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to rebase against main |
||
@classmethod | ||
def utcfromtimestamp(cls, ts: float) -> Self: ... | ||
@classmethod | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,7 @@ from collections.abc import ( | |
MutableMapping, | ||
Sequence, | ||
) | ||
import datetime | ||
import datetime as _dt | ||
import datetime as dt | ||
from re import Pattern | ||
from typing import ( | ||
Any, | ||
|
@@ -373,7 +372,7 @@ class DataFrame(NDFrame, OpsMixin): | |
convert_dates: dict[HashableT1, StataDateFormat] | None = ..., | ||
write_index: _bool = ..., | ||
byteorder: Literal["<", ">", "little", "big"] | None = ..., | ||
time_stamp: _dt.datetime | None = ..., | ||
time_stamp: dt.datetime | None = ..., | ||
data_label: _str | None = ..., | ||
variable_labels: dict[HashableT2, str] | None = ..., | ||
version: Literal[114, 117, 118, 119] | None = ..., | ||
|
@@ -1565,14 +1564,14 @@ class DataFrame(NDFrame, OpsMixin): | |
) -> DataFrame: ... | ||
def at_time( | ||
self, | ||
time: _str | datetime.time, | ||
time: _str | dt.time, | ||
asof: _bool = ..., | ||
axis: Axis | None = ..., | ||
) -> DataFrame: ... | ||
def between_time( | ||
self, | ||
start_time: _str | datetime.time, | ||
end_time: _str | datetime.time, | ||
start_time: _str | dt.time, | ||
end_time: _str | dt.time, | ||
axis: Axis | None = ..., | ||
) -> DataFrame: ... | ||
@overload | ||
|
@@ -1941,7 +1940,7 @@ class DataFrame(NDFrame, OpsMixin): | |
level: Level | None = ..., | ||
origin: Timestamp | ||
| Literal["epoch", "start", "start_day", "end", "end_day"] = ..., | ||
offset: Timedelta | _str | None = ..., | ||
offset: dt.timedelta | _str | None = ..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
group_keys: _bool = ..., | ||
) -> Resampler[DataFrame]: ... | ||
def rfloordiv( | ||
|
@@ -1968,7 +1967,7 @@ class DataFrame(NDFrame, OpsMixin): | |
@overload | ||
def rolling( | ||
self, | ||
window: int | str | _dt.timedelta | BaseOffset | BaseIndexer, | ||
window: int | str | dt.timedelta | BaseOffset | BaseIndexer, | ||
min_periods: int | None = ..., | ||
center: _bool = ..., | ||
on: Hashable | None = ..., | ||
|
@@ -1982,7 +1981,7 @@ class DataFrame(NDFrame, OpsMixin): | |
@overload | ||
def rolling( | ||
self, | ||
window: int | str | _dt.timedelta | BaseOffset | BaseIndexer, | ||
window: int | str | dt.timedelta | BaseOffset | BaseIndexer, | ||
min_periods: int | None = ..., | ||
center: _bool = ..., | ||
on: Hashable | None = ..., | ||
|
@@ -2217,8 +2216,8 @@ class DataFrame(NDFrame, OpsMixin): | |
) -> DataFrame: ... | ||
def truncate( | ||
self, | ||
before: datetime.date | _str | int | None = ..., | ||
after: datetime.date | _str | int | None = ..., | ||
before: dt.date | _str | int | None = ..., | ||
after: dt.date | _str | int | None = ..., | ||
axis: Axis | None = ..., | ||
copy: _bool = ..., | ||
) -> DataFrame: ... | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import datetime as dt | ||
from datetime import tzinfo | ||
from datetime import ( | ||
timedelta, | ||
tzinfo, | ||
) | ||
from typing import ( | ||
Generic, | ||
Literal, | ||
|
@@ -166,21 +169,21 @@ class _DatetimeRoundingMethods(Generic[_DTRoundingMethodReturnType]): | |
freq: str | BaseOffset | None, | ||
ambiguous: Literal["raise", "infer", "NaT"] | np_ndarray_bool = ..., | ||
nonexistent: Literal["shift_forward", "shift_backward", "NaT", "raise"] | ||
| Timedelta = ..., | ||
| timedelta = ..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> _DTRoundingMethodReturnType: ... | ||
def floor( | ||
self, | ||
freq: str | BaseOffset | None, | ||
ambiguous: Literal["raise", "infer", "NaT"] | np_ndarray_bool = ..., | ||
nonexistent: Literal["shift_forward", "shift_backward", "NaT", "raise"] | ||
| Timedelta = ..., | ||
| timedelta = ..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> _DTRoundingMethodReturnType: ... | ||
def ceil( | ||
self, | ||
freq: str | BaseOffset | None, | ||
ambiguous: Literal["raise", "infer", "NaT"] | np_ndarray_bool = ..., | ||
nonexistent: Literal["shift_forward", "shift_backward", "NaT", "raise"] | ||
| Timedelta = ..., | ||
| timedelta = ..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> _DTRoundingMethodReturnType: ... | ||
|
||
_DTNormalizeReturnType = TypeVar( | ||
|
@@ -206,7 +209,7 @@ class _DatetimeLikeNoTZMethods( | |
tz: tzinfo | str | None, | ||
ambiguous: Literal["raise", "infer", "NaT"] | np_ndarray_bool = ..., | ||
nonexistent: Literal["shift_forward", "shift_backward", "NaT", "raise"] | ||
| Timedelta = ..., | ||
| timedelta = ..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> _DTNormalizeReturnType: ... | ||
def tz_convert(self, tz: tzinfo | str | None) -> _DTNormalizeReturnType: ... | ||
def normalize(self) -> _DTNormalizeReturnType: ... | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ from collections.abc import ( | |
Sequence, | ||
) | ||
from datetime import ( | ||
datetime, | ||
timedelta, | ||
tzinfo, | ||
) | ||
|
@@ -59,13 +60,13 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties): | |
@overload | ||
def __add__(self, other: TimedeltaSeries) -> TimestampSeries: ... | ||
@overload | ||
def __add__(self, other: Timedelta | TimedeltaIndex) -> DatetimeIndex: ... | ||
def __add__(self, other: timedelta | TimedeltaIndex) -> DatetimeIndex: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
@overload | ||
def __sub__(self, other: TimedeltaSeries) -> TimestampSeries: ... | ||
@overload | ||
def __sub__(self, other: Timedelta | TimedeltaIndex) -> DatetimeIndex: ... | ||
def __sub__(self, other: timedelta | TimedeltaIndex) -> DatetimeIndex: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
@overload | ||
def __sub__(self, other: Timestamp | DatetimeIndex) -> TimedeltaIndex: ... | ||
def __sub__(self, other: datetime | DatetimeIndex) -> TimedeltaIndex: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
def to_series(self, index=..., name=...) -> TimestampSeries: ... | ||
def snap(self, freq: str = ...): ... | ||
def get_value(self, series, key): ... | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,7 @@ from pandas.core.indexes.period import PeriodIndex | |
from pandas.core.series import TimedeltaSeries | ||
from typing_extensions import Self | ||
|
||
from pandas._libs import ( | ||
Timedelta, | ||
Timestamp, | ||
) | ||
from pandas._libs import Timedelta | ||
from pandas._libs.tslibs import BaseOffset | ||
from pandas._typing import ( | ||
AnyArrayLike, | ||
|
@@ -52,9 +49,9 @@ class TimedeltaIndex(DatetimeTimedeltaMixin[Timedelta], TimedeltaIndexProperties | |
@overload | ||
def __add__(self, other: DatetimeIndex) -> DatetimeIndex: ... | ||
@overload | ||
def __add__(self, other: Timedelta | Self) -> Self: ... | ||
def __radd__(self, other: Timestamp | DatetimeIndex) -> DatetimeIndex: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||
def __sub__(self, other: Timedelta | Self) -> Self: ... | ||
def __add__(self, other: dt.timedelta | Self) -> Self: ... | ||
def __radd__(self, other: dt.datetime | DatetimeIndex) -> DatetimeIndex: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||
def __sub__(self, other: dt.timedelta | Self) -> Self: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
def __mul__(self, other: num) -> Self: ... | ||
@overload # type: ignore[override] | ||
def __truediv__(self, other: num | Sequence[float]) -> Self: ... | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from datetime import timedelta | ||
from typing import ( | ||
Literal, | ||
overload, | ||
|
@@ -8,7 +9,6 @@ from pandas import ( | |
Series, | ||
) | ||
|
||
from pandas._libs.tslibs import Timedelta | ||
from pandas._typing import ( | ||
AnyArrayLike, | ||
HashableT, | ||
|
@@ -99,7 +99,7 @@ def merge_asof( | |
| tuple[str, str] | ||
| tuple[None, str] | ||
| tuple[str, None] = ..., | ||
tolerance: int | Timedelta | None = ..., | ||
tolerance: int | timedelta | None = ..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
allow_exact_matches: bool = ..., | ||
direction: Literal["backward", "forward", "nearest"] = ..., | ||
) -> DataFrame: ... |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1352,9 +1352,9 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
base: int = ..., | ||
on: _str | None = ..., | ||
level: Level | None = ..., | ||
origin: Timestamp | ||
origin: datetime | ||
Dr-Irv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Literal["epoch", "start", "start_day", "end", "end_day"] = ..., | ||
offset: Timedelta | _str | None = ..., | ||
offset: timedelta | _str | None = ..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> Resampler[Series]: ... | ||
def first(self, offset) -> Series[S1]: ... | ||
def last(self, offset) -> Series[S1]: ... | ||
|
@@ -1456,7 +1456,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
def __add__(self, other: S1 | Self) -> Self: ... | ||
@overload | ||
def __add__( | ||
self, other: num | _str | Timedelta | _ListLike | Series | np.timedelta64 | ||
self, other: num | _str | timedelta | _ListLike | Series | np.timedelta64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> Series: ... | ||
# ignore needed for mypy as we want different results based on the arguments | ||
@overload # type: ignore[override] | ||
|
@@ -1485,7 +1485,7 @@ class Series(IndexOpsMixin[S1], NDFrame): | |
) -> Series[_bool]: ... | ||
@overload | ||
def __mul__( | ||
self, other: Timedelta | TimedeltaSeries | np.timedelta64 | ||
self, other: timedelta | TimedeltaSeries | np.timedelta64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> TimedeltaSeries: ... | ||
@overload | ||
def __mul__(self, other: num | _ListLike | Series) -> Series: ... | ||
|
@@ -2043,18 +2043,18 @@ class TimedeltaSeries(Series[Timedelta]): | |
def __add__(self, other: Period) -> PeriodSeries: ... | ||
@overload | ||
def __add__( | ||
self, other: Timestamp | TimestampSeries | DatetimeIndex | ||
self, other: datetime | TimestampSeries | DatetimeIndex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> TimestampSeries: ... | ||
@overload | ||
def __add__( # pyright: ignore[reportIncompatibleMethodOverride] | ||
self, other: Timedelta | np.timedelta64 | ||
self, other: timedelta | np.timedelta64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> TimedeltaSeries: ... | ||
def __radd__(self, other: Timestamp | TimestampSeries) -> TimestampSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||
def __radd__(self, other: datetime | TimestampSeries) -> TimestampSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
def __mul__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||
self, other: num | Sequence[num] | Series[int] | Series[float] | ||
) -> TimedeltaSeries: ... | ||
def __sub__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||
self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 | ||
self, other: timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put back |
||
) -> TimedeltaSeries: ... | ||
@overload # type: ignore[override] | ||
def __truediv__(self, other: float | Sequence[float]) -> Self: ... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put back
Timestamp