Skip to content

Commit 82587f3

Browse files
committed
type PeriodIndex.__new__
1 parent 0f14e32 commit 82587f3

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

pandas-stubs/core/indexes/period.pyi

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections.abc import Hashable
22
import datetime
33
from typing import (
4-
final,
54
overload,
65
)
76

@@ -14,27 +13,27 @@ from pandas.core.indexes.timedeltas import TimedeltaIndex
1413
from typing_extensions import Self
1514

1615
from pandas._libs.tslibs import (
17-
BaseOffset,
1816
NaTType,
1917
Period,
2018
)
2119
from pandas._libs.tslibs.period import _PeriodAddSub
20+
from pandas._typing import (
21+
AxesData,
22+
Dtype,
23+
Frequency,
24+
)
2225

2326
class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexFieldOps):
2427
def __new__(
2528
cls,
26-
data=...,
27-
ordinal=...,
28-
freq=...,
29-
tz=...,
30-
dtype=...,
31-
copy: bool = ...,
32-
name: Hashable = ...,
33-
**fields,
29+
data: AxesData | None = None,
30+
freq: Frequency | None = None,
31+
dtype: Dtype | None = None,
32+
copy: bool = False,
33+
name: Hashable | None = None,
3434
): ...
3535
@property
36-
def values(self): ...
37-
def __contains__(self, key) -> bool: ...
36+
def values(self) -> np.ndarray[tuple[int], np.dtype[np.object_]]: ...
3837
@overload
3938
def __sub__(self, other: Period) -> Index: ...
4039
@overload
@@ -53,28 +52,11 @@ class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexField
5352
def __rsub__( # pyright: ignore[reportIncompatibleMethodOverride]
5453
self, other: NaTType
5554
) -> NaTType: ...
56-
@final
57-
def __array_wrap__(self, result, context=...): ...
5855
def asof_locs(self, where, mask): ...
59-
def searchsorted(self, value, side: str = ..., sorter=...): ...
6056
@property
6157
def is_full(self) -> bool: ...
6258
@property
6359
def inferred_type(self) -> str: ...
64-
@final
65-
def get_indexer(self, target, method=..., limit=..., tolerance=...): ...
66-
def get_indexer_non_unique(self, target): ...
67-
def insert(self, loc, item): ...
68-
@final
69-
def join(
70-
self,
71-
other,
72-
*,
73-
how: str = ...,
74-
level=...,
75-
return_indexers: bool = ...,
76-
sort: bool = ...,
77-
): ...
7860
@property
7961
def freqstr(self) -> str: ...
8062
def shift(self, periods: int = 1, freq=...) -> Self: ...
@@ -87,6 +69,6 @@ def period_range(
8769
str | datetime.datetime | datetime.date | pd.Timestamp | pd.Period | None
8870
) = None,
8971
periods: int | None = None,
90-
freq: str | BaseOffset | None = None,
72+
freq: Frequency | None = None,
9173
name: Hashable | None = None,
9274
) -> PeriodIndex: ...

tests/test_indexes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,3 +1489,16 @@ def test_index_naming() -> None:
14891489
check(assert_type(df.index.names, list[Hashable | None]), list)
14901490
df.index.names = (None,)
14911491
check(assert_type(df.index.names, list[Hashable | None]), list)
1492+
1493+
1494+
def test_period_index_constructor() -> None:
1495+
check(
1496+
assert_type(pd.PeriodIndex(["2000"], dtype="period[D]"), pd.PeriodIndex),
1497+
pd.PeriodIndex,
1498+
)
1499+
check(
1500+
assert_type(
1501+
pd.PeriodIndex(["2000"], freq="D", name="foo", copy=True), pd.PeriodIndex
1502+
),
1503+
pd.PeriodIndex,
1504+
)

0 commit comments

Comments
 (0)