-
-
Notifications
You must be signed in to change notification settings - Fork 144
ENH: Improve Pandas scalars #383
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 all commits
5c0dc1c
9f5058f
7ad615a
fb6d782
fecd9f9
5adba7b
c4dca27
d86adfd
79f56c2
cc390f5
c044a8c
f58c47c
fbfa4c1
ccbde88
25aa8c9
290f951
e62cc10
9c6b963
e93ca54
9070b0d
28e127e
f59c689
2f262d4
7dd8c56
9c2d500
0c2f5ca
e224537
08156cc
1672751
4c3ea13
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 |
---|---|---|
@@ -1,34 +1,120 @@ | ||
from typing import Any | ||
import datetime | ||
from typing import ( | ||
Literal, | ||
Union, | ||
overload, | ||
) | ||
|
||
import numpy as np | ||
from pandas import ( | ||
Index, | ||
PeriodIndex, | ||
Timedelta, | ||
) | ||
from pandas.core.series import ( | ||
PeriodSeries, | ||
TimedeltaSeries, | ||
) | ||
from typing_extensions import TypeAlias | ||
|
||
from pandas._typing import npt | ||
|
||
from .timestamps import Timestamp | ||
|
||
class IncompatibleFrequency(ValueError): ... | ||
|
||
class Period: | ||
from pandas._libs.tslibs.offsets import BaseOffset | ||
|
||
_PeriodAddSub: TypeAlias = Union[ | ||
Timedelta, datetime.timedelta, np.timedelta64, np.int64, int, BaseOffset | ||
] | ||
|
||
_PeriodFreqHow: TypeAlias = Literal[ | ||
"S", | ||
"E", | ||
"Start", | ||
"Finish", | ||
"Begin", | ||
"End", | ||
"s", | ||
"e", | ||
"start", | ||
"finish", | ||
"begin", | ||
"end", | ||
] | ||
|
||
class PeriodMixin: | ||
@property | ||
def end_time(self) -> Timestamp: ... | ||
@property | ||
def start_time(self) -> Timestamp: ... | ||
|
||
class Period(PeriodMixin): | ||
def __init__( | ||
self, | ||
value: Any = ..., | ||
freqstr: Any = ..., | ||
ordinal: Any = ..., | ||
year: Any = ..., | ||
month: int = ..., | ||
quarter: Any = ..., | ||
day: int = ..., | ||
hour: int = ..., | ||
minute: int = ..., | ||
second: int = ..., | ||
value: Period | str | None = ..., | ||
freq: str | BaseOffset | None = ..., | ||
ordinal: int | None = ..., | ||
year: int | None = ..., | ||
month: int | None = ..., | ||
quarter: int | None = ..., | ||
day: int | None = ..., | ||
hour: int | None = ..., | ||
minute: int | None = ..., | ||
second: int | None = ..., | ||
) -> None: ... | ||
def __add__(self, other) -> Period: ... | ||
def __eq__(self, other) -> bool: ... | ||
def __ge__(self, other) -> bool: ... | ||
def __gt__(self, other) -> bool: ... | ||
@overload | ||
def __sub__(self, other: _PeriodAddSub) -> Period: ... | ||
@overload | ||
def __sub__(self, other: Period) -> BaseOffset: ... | ||
@overload | ||
def __sub__(self, other: PeriodIndex) -> Index: ... | ||
@overload | ||
def __sub__(self, other: TimedeltaSeries) -> PeriodSeries: ... | ||
@overload | ||
def __add__(self, other: _PeriodAddSub) -> Period: ... | ||
@overload | ||
def __add__(self, other: Index) -> PeriodIndex: ... | ||
@overload | ||
def __add__(self, other: TimedeltaSeries) -> PeriodSeries: ... | ||
@overload # type: ignore[override] | ||
def __eq__(self, other: Period) -> bool: ... | ||
@overload | ||
def __eq__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... | ||
@overload | ||
def __ge__(self, other: Period) -> bool: ... | ||
@overload | ||
def __ge__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... | ||
@overload | ||
def __gt__(self, other: Period) -> bool: ... | ||
@overload | ||
def __gt__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... | ||
def __hash__(self) -> int: ... | ||
def __le__(self, other) -> bool: ... | ||
def __lt__(self, other) -> bool: ... | ||
def __new__(cls, *args, **kwargs) -> Period: ... | ||
def __ne__(self, other) -> bool: ... | ||
def __radd__(self, other) -> Period: ... | ||
def __reduce__(self, *args, **kwargs) -> Any: ... # what should this be? | ||
def __rsub__(self, other) -> Period: ... | ||
def __setstate__(self, *args, **kwargs) -> Any: ... # what should this be? | ||
@overload | ||
def __le__(self, other: Period) -> bool: ... | ||
@overload | ||
def __le__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... | ||
@overload | ||
def __lt__(self, other: Period) -> bool: ... | ||
@overload | ||
def __lt__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... | ||
@overload # type: ignore[override] | ||
def __ne__(self, other: Period) -> bool: ... | ||
@overload | ||
def __ne__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... | ||
# Ignored due to indecipherable error from mypy: | ||
# Forward operator "__add__" is not callable [misc] | ||
@overload | ||
def __radd__(self, other: _PeriodAddSub) -> Period: ... # type: ignore[misc] | ||
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. I think the error might be due to having conflicts between one of the 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. I think it is because Period + Index -> PeriodIndex here but Index + Period -> Index there. |
||
# Real signature is -> PeriodIndex, but conflicts with Index.__add__ | ||
# Changing Index is very hard due to Index inheritance | ||
# Signatures of "__radd__" of "Period" and "__add__" of "Index" | ||
# are unsafely overlapping | ||
@overload | ||
def __radd__(self, other: Index) -> Index: ... | ||
@overload | ||
def __radd__(self, other: TimedeltaSeries) -> PeriodSeries: ... | ||
@property | ||
def day(self) -> int: ... | ||
@property | ||
|
@@ -42,7 +128,7 @@ class Period: | |
@property | ||
def end_time(self) -> Timestamp: ... | ||
@property | ||
def freq(self) -> Any: ... | ||
def freq(self) -> BaseOffset: ... | ||
@property | ||
def freqstr(self) -> str: ... | ||
@property | ||
|
@@ -71,12 +157,16 @@ class Period: | |
def weekofyear(self) -> int: ... | ||
@property | ||
def year(self) -> int: ... | ||
# Static methods | ||
@property | ||
def day_of_year(self) -> int: ... | ||
@property | ||
def day_of_week(self) -> int: ... | ||
def asfreq(self, freq: str | BaseOffset, how: _PeriodFreqHow = ...) -> Period: ... | ||
bashtage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@classmethod | ||
def now(cls) -> Period: ... | ||
# Methods | ||
def asfreq(self, freq: str, how: str = ...) -> Period: ... | ||
def now(cls, freq: str | BaseOffset = ...) -> Period: ... | ||
bashtage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def strftime(self, fmt: str) -> str: ... | ||
def to_timestamp(self, freq: str, how: str = ...) -> Timestamp: ... | ||
|
||
from .timestamps import Timestamp | ||
def to_timestamp( | ||
self, | ||
freq: str | BaseOffset | None = ..., | ||
how: _PeriodFreqHow = ..., | ||
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. I think these arguments are correct. 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. Are you missing a "do not" before think? Not sure how to interpret this comment since it seems to be saying I have them correct. They are all tested FWIW. |
||
) -> Timestamp: ... |
Uh oh!
There was an error while loading. Please reload this page.