Skip to content

Commit f319951

Browse files
committed
two more test files
1 parent aa94c9c commit f319951

File tree

5 files changed

+64
-23
lines changed

5 files changed

+64
-23
lines changed

pandas-stubs/core/arrays/__init__.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ from pandas.core.arrays.integer import IntegerArray
1212
from pandas.core.arrays.interval import IntervalArray
1313
from pandas.core.arrays.masked import BaseMaskedArray
1414
from pandas.core.arrays.numpy_ import NumpyExtensionArray
15-
from pandas.core.arrays.period import (
16-
PeriodArray,
17-
period_array,
18-
)
15+
from pandas.core.arrays.period import PeriodArray
1916
from pandas.core.arrays.sparse import SparseArray
2017
from pandas.core.arrays.string_ import StringArray
2118
from pandas.core.arrays.string_arrow import ArrowStringArray
@@ -39,5 +36,4 @@ __all__ = [
3936
"SparseArray",
4037
"StringArray",
4138
"TimedeltaArray",
42-
"period_array",
4339
]

pandas-stubs/core/arrays/period.pyi

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
from collections.abc import Sequence
2-
31
from pandas import PeriodDtype
42
from pandas.core.arrays.datetimelike import (
53
DatelikeOps,
64
DatetimeLikeArrayMixin,
75
)
86

97
from pandas._libs.tslibs import Timestamp
10-
from pandas._libs.tslibs.offsets import (
11-
BaseOffset,
12-
Tick,
13-
)
148
from pandas._libs.tslibs.period import Period
159
from pandas._typing import (
16-
AnyArrayLike,
1710
NpDtype,
1811
PeriodFrequency,
1912
np_1darray,
@@ -54,9 +47,3 @@ class PeriodArray(DatetimeLikeArrayMixin, DatelikeOps):
5447
self, freq: PeriodFrequency | None = None, how: str = ...
5548
) -> Timestamp: ...
5649
def asfreq(self, freq: str | None = ..., how: str = "E") -> Period: ...
57-
58-
def period_array(
59-
data: Sequence[Period | str | None] | AnyArrayLike,
60-
freq: str | Tick | BaseOffset | None = None,
61-
copy: bool = False,
62-
) -> PeriodArray: ...

pandas-stubs/core/construction.pyi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@ def array(
128128
copy: bool = True,
129129
) -> StringArray: ...
130130
@overload
131-
def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
132-
data: Sequence[Period | NAType | None] | PeriodArray | PeriodIndex | Series[Period],
131+
def array( # type: ignore[overload-overlap]
132+
data: (
133+
Sequence[Period | NaTType | None] | PeriodArray | PeriodIndex | Series[Period]
134+
),
133135
dtype: PeriodDtype | None = None,
134136
copy: bool = True,
135-
) -> PeriodIndex: ...
137+
) -> PeriodArray: ...
136138
@overload
137139
def array( # type: ignore[overload-overlap]
138140
data: (
@@ -157,11 +159,11 @@ def array(
157159
copy: bool = True,
158160
) -> NumpyExtensionArray: ...
159161
@overload
160-
def array( # type: ignore[overload-overlap]
162+
def array(
161163
data: SparseArray | SparseIndex,
162164
dtype: str | np.dtype | ExtensionDtype | None = None,
163165
copy: bool = True,
164-
) -> SparseIndex: ...
166+
) -> SparseArray: ...
165167
@overload
166168
def array(
167169
data: ArrowExtensionArray,

tests/arrays/test_period_array.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pandas as pd
2+
from pandas.core.arrays.period import PeriodArray
3+
from typing_extensions import assert_type
4+
5+
from tests import check
6+
7+
8+
def test_constructor() -> None:
9+
prd = pd.Period("2023-01-01")
10+
check(
11+
assert_type( # type: ignore[assert-type] # I do not understand
12+
pd.array([prd]), PeriodArray
13+
),
14+
PeriodArray,
15+
)
16+
check(
17+
assert_type( # type: ignore[assert-type] # I do not understand
18+
pd.array([prd, None]), PeriodArray
19+
),
20+
PeriodArray,
21+
)
22+
check(
23+
assert_type( # type: ignore[assert-type] # I do not understand
24+
pd.array([prd, pd.NaT, None]), PeriodArray
25+
),
26+
PeriodArray,
27+
)
28+
29+
check(
30+
assert_type( # type: ignore[assert-type] # I do not understand
31+
pd.array(pd.array([prd])), PeriodArray
32+
),
33+
PeriodArray,
34+
)
35+
36+
check(assert_type(pd.array(pd.Index([prd])), PeriodArray), PeriodArray)
37+
38+
check(assert_type(pd.array(pd.Series([prd])), PeriodArray), PeriodArray)

tests/arrays/test_string_array.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import numpy as np
2+
import pandas as pd
3+
from pandas.core.arrays.string_ import StringArray
4+
from typing_extensions import assert_type
5+
6+
from tests import check
7+
8+
9+
def test_constructor() -> None:
10+
check(assert_type(pd.array(["🐼"]), StringArray), StringArray)
11+
check(
12+
assert_type(pd.array(["🐼", np.str_("🐼")]), StringArray),
13+
StringArray,
14+
)
15+
check(assert_type(pd.array(["🐼", None]), StringArray), StringArray)
16+
check(assert_type(pd.array(["🐼", pd.NA, None]), StringArray), StringArray)
17+
18+
check(assert_type(pd.array(pd.array(["🐼"])), StringArray), StringArray)

0 commit comments

Comments
 (0)