Skip to content

Commit 09bde05

Browse files
committed
MAINT: Merge main
2 parents 67248e0 + 9b10f67 commit 09bde05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2892
-211
lines changed

.github/setup/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ runs:
2121

2222
- name: Determine poetry version
2323
shell: bash
24-
run: echo "::set-output name=VERSION::$(poetry --version)"
24+
run: echo "{VERSION}=$(poetry --version)"
2525
id: poetry_version
2626

2727
- name: Cache poetry.lock

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
os: [ubuntu-latest, windows-latest, macos-latest]
17-
python-version: ['3.8', '3.9', '3.10.6']
17+
python-version: ['3.8', '3.9', '3.10.6', '3.11']
1818

1919
steps:
2020
- uses: actions/checkout@v3

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
hooks:
1212
- id: isort
1313
- repo: https://github.com/asottile/pyupgrade
14-
rev: v2.37.3
14+
rev: v3.2.0
1515
hooks:
1616
- id: pyupgrade
1717
types_or: [python, pyi]
@@ -27,7 +27,7 @@ repos:
2727
- id: flake8
2828
name: flake8 (pyi)
2929
additional_dependencies:
30-
- flake8-pyi==22.8.2
30+
- flake8-pyi==22.10.0
3131
types: [pyi]
3232
args: [
3333
--ignore=E301 E302 E305 E402 E501 E701 E704 F401 F811 W503 Y019 Y027 Y034 Y037 Y041 Y042,

pandas-stubs/_libs/tslibs/offsets.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import (
22
date,
33
datetime,
4+
time,
45
timedelta,
56
)
67
from typing import (
@@ -78,6 +79,7 @@ class BaseOffset:
7879
def name(self) -> str: ...
7980
@property
8081
def rule_code(self) -> str: ...
82+
@property
8183
def freqstr(self) -> str: ...
8284
def apply_index(self, dtindex: DatetimeIndex) -> DatetimeIndex: ...
8385
def rollback(self, dt: datetime) -> datetime: ...
@@ -131,8 +133,8 @@ class BusinessHour(BusinessMixin):
131133
self,
132134
n: int = ...,
133135
normalize: bool = ...,
134-
start: str | Collection[str] = ...,
135-
end: str | Collection[str] = ...,
136+
start: str | time | Collection[str | time] = ...,
137+
end: str | time | Collection[str | time] = ...,
136138
offset: timedelta = ...,
137139
): ...
138140

@@ -217,8 +219,8 @@ class CustomBusinessHour(BusinessHour):
217219
self,
218220
n: int = ...,
219221
normalize: bool = ...,
220-
start: str = ...,
221-
end: str = ...,
222+
start: str | time | Collection[str | time] = ...,
223+
end: str | time | Collection[str | time] = ...,
222224
offset: timedelta = ...,
223225
holidays: list | None = ...,
224226
): ...

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 157 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,157 @@
1-
from typing import Any
1+
import datetime
2+
from typing import (
3+
Literal,
4+
Union,
5+
overload,
6+
)
7+
8+
import numpy as np
9+
from pandas import (
10+
Index,
11+
PeriodIndex,
12+
Series,
13+
Timedelta,
14+
TimedeltaIndex,
15+
)
16+
from pandas.core.series import (
17+
OffsetSeries,
18+
PeriodSeries,
19+
TimedeltaSeries,
20+
)
21+
from typing_extensions import TypeAlias
22+
23+
from pandas._libs.tslibs import NaTType
24+
from pandas._typing import npt
25+
26+
from .timestamps import Timestamp
227

328
class IncompatibleFrequency(ValueError): ...
429

530
from pandas._libs.tslibs.offsets import BaseOffset
631

7-
class Period:
32+
_PeriodAddSub: TypeAlias = Union[
33+
Timedelta, datetime.timedelta, np.timedelta64, np.int64, int, BaseOffset
34+
]
35+
36+
_PeriodFreqHow: TypeAlias = Literal[
37+
"S",
38+
"E",
39+
"start",
40+
"end",
41+
]
42+
43+
_PeriodToTimestampHow: TypeAlias = Union[
44+
_PeriodFreqHow,
45+
Literal[
46+
"Start",
47+
"Finish",
48+
"Begin",
49+
"End",
50+
"s",
51+
"e",
52+
"finish",
53+
"begin",
54+
],
55+
]
56+
57+
class PeriodMixin:
58+
@property
59+
def end_time(self) -> Timestamp: ...
60+
@property
61+
def start_time(self) -> Timestamp: ...
62+
63+
class Period(PeriodMixin):
864
def __init__(
965
self,
10-
value: Any = ...,
66+
value: Period | str | None = ...,
1167
freq: str | BaseOffset | None = ...,
12-
ordinal: Any = ...,
13-
year: Any = ...,
14-
month: int = ...,
15-
quarter: Any = ...,
16-
day: int = ...,
17-
hour: int = ...,
18-
minute: int = ...,
19-
second: int = ...,
68+
ordinal: int | None = ...,
69+
year: int | None = ...,
70+
month: int | None = ...,
71+
quarter: int | None = ...,
72+
day: int | None = ...,
73+
hour: int | None = ...,
74+
minute: int | None = ...,
75+
second: int | None = ...,
2076
) -> None: ...
21-
def __add__(self, other) -> Period: ...
22-
def __eq__(self, other) -> bool: ...
23-
def __ge__(self, other) -> bool: ...
24-
def __gt__(self, other) -> bool: ...
25-
def __hash__(self) -> int: ...
26-
def __le__(self, other) -> bool: ...
27-
def __lt__(self, other) -> bool: ...
28-
def __new__(cls, *args, **kwargs) -> Period: ...
29-
def __ne__(self, other) -> bool: ...
30-
def __radd__(self, other) -> Period: ...
31-
def __reduce__(self, *args, **kwargs) -> Any: ... # what should this be?
32-
def __rsub__(self, other) -> Period: ...
33-
def __setstate__(self, *args, **kwargs) -> Any: ... # what should this be?
77+
@overload
78+
def __sub__(self, other: _PeriodAddSub) -> Period: ...
79+
@overload
80+
def __sub__(self, other: Period) -> BaseOffset: ...
81+
@overload
82+
def __sub__(self, other: NaTType) -> NaTType: ...
83+
@overload
84+
def __sub__(self, other: PeriodIndex) -> Index: ...
85+
@overload
86+
def __sub__(self, other: TimedeltaSeries) -> PeriodSeries: ...
87+
@overload
88+
def __sub__(self, other: TimedeltaIndex) -> PeriodIndex: ...
89+
@overload
90+
def __add__(self, other: _PeriodAddSub) -> Period: ...
91+
@overload
92+
def __add__(self, other: NaTType) -> NaTType: ...
93+
@overload
94+
def __add__(self, other: Index) -> PeriodIndex: ...
95+
@overload
96+
def __add__(self, other: OffsetSeries | TimedeltaSeries) -> PeriodSeries: ...
97+
# ignore[misc] here because we know all other comparisons
98+
# are False, so we use Literal[False]
99+
@overload
100+
def __eq__(self, other: Period) -> bool: ... # type: ignore[misc]
101+
@overload
102+
def __eq__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... # type: ignore[misc]
103+
@overload
104+
def __eq__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... # type: ignore[misc]
105+
@overload
106+
def __eq__(self, other: object) -> Literal[False]: ...
107+
@overload
108+
def __ge__(self, other: Period) -> bool: ...
109+
@overload
110+
def __ge__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ...
111+
@overload
112+
def __ge__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ...
113+
@overload
114+
def __gt__(self, other: Period) -> bool: ...
115+
@overload
116+
def __gt__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ...
117+
@overload
118+
def __gt__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ...
119+
@overload
120+
def __le__(self, other: Period) -> bool: ...
121+
@overload
122+
def __le__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ...
123+
@overload
124+
def __le__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ...
125+
@overload
126+
def __lt__(self, other: Period) -> bool: ...
127+
@overload
128+
def __lt__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ...
129+
@overload
130+
def __lt__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ...
131+
# ignore[misc] here because we know all other comparisons
132+
# are False, so we use Literal[False]
133+
@overload
134+
def __ne__(self, other: Period) -> bool: ... # type: ignore[misc]
135+
@overload
136+
def __ne__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... # type: ignore[misc]
137+
@overload
138+
def __ne__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... # type: ignore[misc]
139+
@overload
140+
def __ne__(self, other: object) -> Literal[True]: ...
141+
# Ignored due to indecipherable error from mypy:
142+
# Forward operator "__add__" is not callable [misc]
143+
@overload
144+
def __radd__(self, other: _PeriodAddSub) -> Period: ... # type: ignore[misc]
145+
# Real signature is -> PeriodIndex, but conflicts with Index.__add__
146+
# Changing Index is very hard due to Index inheritance
147+
# Signatures of "__radd__" of "Period" and "__add__" of "Index"
148+
# are unsafely overlapping
149+
@overload
150+
def __radd__(self, other: Index) -> Index: ...
151+
@overload
152+
def __radd__(self, other: TimedeltaSeries) -> PeriodSeries: ...
153+
@overload
154+
def __radd__(self, other: NaTType) -> NaTType: ...
34155
@property
35156
def day(self) -> int: ...
36157
@property
@@ -44,7 +165,7 @@ class Period:
44165
@property
45166
def end_time(self) -> Timestamp: ...
46167
@property
47-
def freq(self) -> Any: ...
168+
def freq(self) -> BaseOffset: ...
48169
@property
49170
def freqstr(self) -> str: ...
50171
@property
@@ -73,12 +194,16 @@ class Period:
73194
def weekofyear(self) -> int: ...
74195
@property
75196
def year(self) -> int: ...
76-
# Static methods
197+
@property
198+
def day_of_year(self) -> int: ...
199+
@property
200+
def day_of_week(self) -> int: ...
201+
def asfreq(self, freq: str | BaseOffset, how: _PeriodFreqHow = ...) -> Period: ...
77202
@classmethod
78-
def now(cls) -> Period: ...
79-
# Methods
80-
def asfreq(self, freq: str, how: str = ...) -> Period: ...
203+
def now(cls, freq: str | BaseOffset = ...) -> Period: ...
81204
def strftime(self, fmt: str) -> str: ...
82-
def to_timestamp(self, freq: str, how: str = ...) -> Timestamp: ...
83-
84-
from .timestamps import Timestamp
205+
def to_timestamp(
206+
self,
207+
freq: str | BaseOffset | None = ...,
208+
how: _PeriodToTimestampHow = ...,
209+
) -> Timestamp: ...

0 commit comments

Comments
 (0)