Skip to content

Commit 1d3705a

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

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

pandas-stubs/core/indexes/period.pyi

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from typing import (
66
)
77

88
import numpy as np
9+
import numpy.typing as npt
910
import pandas as pd
1011
from pandas import Index
1112
from pandas.core.indexes.accessors import PeriodIndexFieldOps
@@ -14,27 +15,27 @@ from pandas.core.indexes.timedeltas import TimedeltaIndex
1415
from typing_extensions import Self
1516

1617
from pandas._libs.tslibs import (
17-
BaseOffset,
1818
NaTType,
1919
Period,
2020
)
2121
from pandas._libs.tslibs.period import _PeriodAddSub
22+
from pandas._typing import (
23+
AxesData,
24+
Dtype,
25+
Frequency,
26+
)
2227

2328
class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexFieldOps):
2429
def __new__(
2530
cls,
26-
data=...,
27-
ordinal=...,
28-
freq=...,
29-
tz=...,
30-
dtype=...,
31-
copy: bool = ...,
32-
name: Hashable = ...,
33-
**fields,
31+
data: AxesData | None = None,
32+
freq: Frequency | None = None,
33+
dtype: Dtype | None = None,
34+
copy: bool = False,
35+
name: Hashable | None = None,
3436
): ...
3537
@property
36-
def values(self): ...
37-
def __contains__(self, key) -> bool: ...
38+
def values(self) -> npt.NDArray[np.object_]: ...
3839
@overload
3940
def __sub__(self, other: Period) -> Index: ...
4041
@overload
@@ -53,8 +54,6 @@ class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexField
5354
def __rsub__( # pyright: ignore[reportIncompatibleMethodOverride]
5455
self, other: NaTType
5556
) -> NaTType: ...
56-
@final
57-
def __array_wrap__(self, result, context=...): ...
5857
def asof_locs(self, where, mask): ...
5958
def searchsorted(self, value, side: str = ..., sorter=...): ...
6059
@property
@@ -87,6 +86,6 @@ def period_range(
8786
str | datetime.datetime | datetime.date | pd.Timestamp | pd.Period | None
8887
) = None,
8988
periods: int | None = None,
90-
freq: str | BaseOffset | None = None,
89+
freq: Frequency | None = None,
9190
name: Hashable | None = None,
9291
) -> 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)