Skip to content

Commit 290f951

Browse files
committed
BUG: Correct errors in period and interval
1 parent 25aa8c9 commit 290f951

File tree

3 files changed

+78
-79
lines changed

3 files changed

+78
-79
lines changed

pandas-stubs/_libs/interval.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
6363
def right(self: Interval[_OrderableT]) -> _OrderableT: ...
6464
@property
6565
def closed(self) -> IntervalClosedType: ...
66-
@property
67-
def mid(self) -> _MidDescriptor: ...
68-
@property
69-
def length(self) -> _LengthDescriptor: ...
66+
mid: _MidDescriptor
67+
length: _LengthDescriptor
7068
def __init__(
7169
self,
7270
left: _OrderableT,

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
from datetime import tzinfo
12
from typing import Any
23

4+
from .timestamps import Timestamp
5+
36
class IncompatibleFrequency(ValueError): ...
47

5-
class Period:
8+
from pandas._libs.tslibs.offsets import BaseOffset
9+
10+
class PeriodMixin:
11+
@property
12+
def end_time(self) -> Timestamp: ...
13+
@property
14+
def start_time(self) -> Timestamp: ...
15+
16+
class Period(PeriodMixin):
617
def __init__(
718
self,
819
value: Any = ...,
@@ -16,14 +27,27 @@ class Period:
1627
minute: int = ...,
1728
second: int = ...,
1829
) -> None: ...
30+
def __new__(
31+
cls,
32+
value: Period | str = ...,
33+
freq: int | str | BaseOffset | None = ...,
34+
ordinal: int | None = ...,
35+
year: int | None = ...,
36+
month: int | None = ...,
37+
quarter: int | None = ...,
38+
day: int | None = ...,
39+
hour: int | None = ...,
40+
minute: int | None = ...,
41+
second: int | None = ...,
42+
) -> Period: ...
43+
def __sub__(self, other) -> Period | BaseOffset: ...
1944
def __add__(self, other) -> Period: ...
2045
def __eq__(self, other) -> bool: ...
2146
def __ge__(self, other) -> bool: ...
2247
def __gt__(self, other) -> bool: ...
2348
def __hash__(self) -> int: ...
2449
def __le__(self, other) -> bool: ...
2550
def __lt__(self, other) -> bool: ...
26-
def __new__(cls, *args, **kwargs) -> Period: ...
2751
def __ne__(self, other) -> bool: ...
2852
def __radd__(self, other) -> Period: ...
2953
def __reduce__(self, *args, **kwargs) -> Any: ... # what should this be?
@@ -71,12 +95,18 @@ class Period:
7195
def weekofyear(self) -> int: ...
7296
@property
7397
def year(self) -> int: ...
74-
# Static methods
98+
@property
99+
def day_of_year(self) -> int: ...
100+
@property
101+
def day_of_week(self) -> int: ...
102+
def asfreq(self, freq: str | BaseOffset, how: str = ...) -> Period: ...
75103
@classmethod
76-
def now(cls) -> Period: ...
77-
# Methods
78-
def asfreq(self, freq: str, how: str = ...) -> Period: ...
104+
def now(cls, freq: BaseOffset = ...) -> Period: ...
79105
def strftime(self, fmt: str) -> str: ...
80-
def to_timestamp(self, freq: str, how: str = ...) -> Timestamp: ...
81-
82-
from .timestamps import Timestamp
106+
def to_timestamp(
107+
self,
108+
freq: str | BaseOffset | None = ...,
109+
how: str = ...,
110+
tz: str | tzinfo | None = ...,
111+
) -> Timestamp: ...
112+
def astype(self, dtype, copy: bool = ...): ...

pandas-stubs/core/arrays/period.pyi

Lines changed: 37 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,51 @@
1-
from datetime import tzinfo
1+
from typing import Sequence
22

33
import numpy as np
4+
from pandas.core.arrays.datetimelike import (
5+
DatelikeOps,
6+
DatetimeLikeArrayMixin,
7+
)
48

5-
from pandas._libs.tslibs.nattype import NaTType
6-
from pandas._libs.tslibs.offsets import BaseOffset
9+
from pandas._libs.tslibs import Period
710
from pandas._libs.tslibs.timestamps import Timestamp
811
from pandas._typing import npt as npt
912

10-
class PeriodMixin:
11-
@property
12-
def end_time(self) -> Timestamp: ...
13-
@property
14-
def start_time(self) -> Timestamp: ...
13+
from pandas.tseries.offsets import Tick
1514

16-
class Period(PeriodMixin):
17-
ordinal: int
18-
freq: BaseOffset
19-
def __new__(
20-
cls,
21-
value: Period | str = ...,
22-
freq: int | str | BaseOffset | None = ...,
23-
ordinal: int | None = ...,
24-
year: int | None = ...,
25-
month: int | None = ...,
26-
quarter: int | None = ...,
27-
day: int | None = ...,
28-
hour: int | None = ...,
29-
minute: int | None = ...,
30-
second: int | None = ...,
31-
) -> Period | NaTType: ...
32-
@classmethod
33-
def now(cls, freq: BaseOffset = ...) -> Period: ...
34-
def strftime(self, fmt: str) -> str: ...
35-
def to_timestamp(
36-
self,
37-
freq: str | BaseOffset | None = ...,
38-
how: str = ...,
39-
tz: str | tzinfo | None = ...,
40-
) -> Timestamp: ...
41-
def asfreq(self, freq: str | BaseOffset, how: str = ...) -> Period: ...
42-
@property
43-
def freqstr(self) -> str: ...
15+
class PeriodArray(DatetimeLikeArrayMixin, DatelikeOps):
16+
__array_priority__: int = ...
17+
def __init__(self, values, freq=..., dtype=..., copy: bool = ...) -> None: ...
18+
def dtype(self): ...
19+
def __array__(self, dtype=...) -> np.ndarray: ...
20+
def __arrow_array__(self, type=...): ...
21+
year: int = ...
22+
month: int = ...
23+
day: int = ...
24+
hour: int = ...
25+
minute: int = ...
26+
second: int = ...
27+
weekofyear: int = ...
28+
week: int = ...
29+
dayofweek: int = ...
30+
weekday: int = ...
31+
dayofyear: int = ...
32+
day_of_year = ...
33+
quarter: int = ...
34+
qyear: int = ...
35+
days_in_month: int = ...
36+
daysinmonth: int = ...
4437
@property
4538
def is_leap_year(self) -> bool: ...
4639
@property
47-
def daysinmonth(self) -> int: ...
48-
@property
49-
def days_in_month(self) -> int: ...
50-
@property
51-
def qyear(self) -> int: ...
52-
@property
53-
def quarter(self) -> int: ...
54-
@property
55-
def day_of_year(self) -> int: ...
56-
@property
57-
def weekday(self) -> int: ...
58-
@property
59-
def day_of_week(self) -> int: ...
60-
@property
61-
def week(self) -> int: ...
62-
@property
63-
def weekofyear(self) -> int: ...
64-
@property
65-
def second(self) -> int: ...
66-
@property
67-
def minute(self) -> int: ...
68-
@property
69-
def hour(self) -> int: ...
70-
@property
71-
def day(self) -> int: ...
72-
@property
73-
def month(self) -> int: ...
40+
def start_time(self) -> Timestamp: ...
7441
@property
75-
def year(self) -> int: ...
76-
def __sub__(self, other) -> Period | BaseOffset: ...
77-
def __add__(self, other) -> Period: ...
42+
def end_time(self) -> Timestamp: ...
7843
def to_timestamp(self, freq: str | None = ..., how: str = ...) -> Timestamp: ...
7944
def asfreq(self, freq: str | None = ..., how: str = ...) -> Period: ...
8045
def astype(self, dtype, copy: bool = ...): ...
46+
47+
def period_array(
48+
data: Sequence[Period | None],
49+
freq: str | Tick | None = ...,
50+
copy: bool = ...,
51+
) -> PeriodArray: ...

0 commit comments

Comments
 (0)