Skip to content

Commit edd3215

Browse files
committed
remove internal APIs and add tests
1 parent 371d3ad commit edd3215

File tree

7 files changed

+164
-151
lines changed

7 files changed

+164
-151
lines changed

pandas-stubs/core/arrays/boolean.pyi

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from collections.abc import Sequence
2-
from typing import Any
32

43
import numpy as np
54
from pandas.core.arrays.integer import IntegerArray
65
from pandas.core.arrays.masked import BaseMaskedArray as BaseMaskedArray
6+
from pandas.core.indexes.base import Index
7+
from pandas.core.series import Series
78
from typing_extensions import Self
89

910
from pandas._libs.missing import NAType
@@ -22,13 +23,21 @@ class BooleanDtype(ExtensionDtype):
2223

2324
class BooleanArray(BaseMaskedArray):
2425
def __init__(
25-
self, values: np_ndarray_bool, mask: np_ndarray_bool, copy: bool = ...
26+
self,
27+
values: (
28+
Sequence[bool | np.bool]
29+
| np_ndarray_bool
30+
| Index[bool]
31+
| Series[bool]
32+
| Self
33+
),
34+
mask: np_ndarray_bool,
35+
copy: bool = False,
2636
) -> None: ...
2737
@property
28-
def dtype(self): ...
29-
def __setitem__(self, key, value) -> None: ...
30-
def any(self, *, skipna: bool = ..., **kwargs: Any): ...
31-
def all(self, *, skipna: bool = ..., **kwargs: Any): ...
38+
def dtype( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
39+
self,
40+
) -> np.dtypes.BoolDType: ...
3241
def __and__(
3342
self,
3443
other: (
Lines changed: 20 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,33 @@
1-
from datetime import tzinfo as _tzinfo
1+
from collections.abc import Sequence
2+
from datetime import datetime
23

34
import numpy as np
45
from pandas.core.arrays.datetimelike import (
56
DatelikeOps,
67
DatetimeLikeArrayMixin,
78
TimelikeOps,
89
)
10+
from pandas.core.indexes.datetimes import DatetimeIndex
11+
from pandas.core.series import Series
12+
from typing_extensions import Self
913

10-
from pandas._typing import (
11-
TimeAmbiguous,
12-
TimeNonexistent,
13-
TimeZones,
14-
)
15-
16-
from pandas.core.dtypes.dtypes import DatetimeTZDtype as DatetimeTZDtype
14+
from pandas._libs.tslibs.timestamps import Timestamp
1715

1816
class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps):
1917
__array_priority__: int = ...
20-
def __init__(self, values, dtype=..., freq=..., copy: bool = ...) -> None: ...
21-
# ignore in dtype() is from the pandas source
22-
@property
23-
def dtype(self) -> np.dtype | DatetimeTZDtype: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
24-
@property
25-
def tz(self): ...
26-
@tz.setter
27-
def tz(self, value) -> None: ...
28-
@property
29-
def tzinfo(self) -> _tzinfo | None: ...
30-
@property
31-
def is_normalized(self): ...
32-
def __iter__(self): ...
33-
def tz_convert(self, tz: TimeZones): ...
34-
def tz_localize(
18+
def __init__(
3519
self,
36-
tz: TimeZones,
37-
ambiguous: TimeAmbiguous = "raise",
38-
nonexistent: TimeNonexistent = "raise",
39-
): ...
40-
def to_pydatetime(self): ...
41-
def normalize(self): ...
42-
def to_period(self, freq=...): ...
43-
def to_perioddelta(self, freq): ...
44-
def month_name(self, locale=...): ...
45-
def day_name(self, locale=...): ...
46-
@property
47-
def time(self): ...
48-
@property
49-
def timetz(self): ...
20+
values: (
21+
Sequence[datetime | np.datetime64]
22+
| np.typing.NDArray[np.datetime64]
23+
| DatetimeIndex
24+
| Series[Timestamp]
25+
| Self
26+
),
27+
dtype: np.dtype | None = None,
28+
copy: bool = False,
29+
) -> None: ...
5030
@property
51-
def date(self): ...
52-
year = ...
53-
month = ...
54-
day = ...
55-
hour = ...
56-
minute = ...
57-
second = ...
58-
microsecond = ...
59-
nanosecond = ...
60-
dayofweek = ...
61-
weekday = ...
62-
dayofyear = ...
63-
quarter = ...
64-
days_in_month = ...
65-
daysinmonth = ...
66-
is_month_start = ...
67-
is_month_end = ...
68-
is_quarter_start = ...
69-
is_quarter_end = ...
70-
is_year_start = ...
71-
is_year_end = ...
72-
is_leap_year = ...
73-
def to_julian_date(self): ...
74-
75-
def objects_to_datetime64ns(
76-
data,
77-
dayfirst,
78-
yearfirst,
79-
utc: bool = ...,
80-
errors: str = ...,
81-
require_iso8601: bool = ...,
82-
allow_object: bool = ...,
83-
): ...
31+
def dtype( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
32+
self,
33+
) -> np.dtypes.DateTime64DType: ...
Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,38 @@
11
from collections.abc import Sequence
22
from datetime import timedelta
33

4+
import numpy as np
45
from pandas.core.arrays.datetimelike import (
56
DatetimeLikeArrayMixin,
67
TimelikeOps,
78
)
9+
from pandas.core.indexes.timedeltas import TimedeltaIndex
10+
from pandas.core.series import Series
11+
from typing_extensions import Self
12+
13+
from pandas._libs.tslibs.timedeltas import Timedelta
14+
from pandas._typing import np_1darray
15+
16+
from pandas.core.dtypes.base import ExtensionDtype
817

918
class TimedeltaArray(DatetimeLikeArrayMixin, TimelikeOps):
1019
__array_priority__: int = ...
1120
@property
12-
def dtype(self): ...
13-
def __init__(self, values, dtype=..., freq=..., copy: bool = ...) -> None: ...
14-
def sum(
15-
self,
16-
*,
17-
axis=...,
18-
dtype=...,
19-
out=...,
20-
keepdims: bool = ...,
21-
initial=...,
22-
skipna: bool = ...,
23-
min_count: int = ...,
24-
): ...
25-
def std(
26-
self,
27-
*,
28-
axis=...,
29-
dtype=...,
30-
out=...,
31-
ddof: int = ...,
32-
keepdims: bool = ...,
33-
skipna: bool = ...,
34-
): ...
35-
def median(
21+
def dtype( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
3622
self,
23+
) -> np.dtypes.TimeDelta64DType: ...
24+
def __init__(self, values, dtype=..., freq=..., copy: bool = ...) -> None: ...
25+
@classmethod
26+
def _from_sequence(
27+
cls,
28+
data: (
29+
Sequence[timedelta | np.timedelta64]
30+
| np_1darray[np.timedelta64]
31+
| TimedeltaIndex
32+
| Series[Timedelta]
33+
| Self
34+
),
3735
*,
38-
axis=...,
39-
out=...,
40-
overwrite_input: bool = ...,
41-
keepdims: bool = ...,
42-
skipna: bool = ...,
43-
): ...
44-
def __mul__(self, other): ...
45-
__rmul__ = ...
46-
def __truediv__(self, other): ...
47-
def __rtruediv__(self, other): ...
48-
def __floordiv__(self, other): ...
49-
def __rfloordiv__(self, other): ...
50-
def __mod__(self, other): ...
51-
def __rmod__(self, other): ...
52-
def __divmod__(self, other): ...
53-
def __rdivmod__(self, other): ...
54-
def __neg__(self): ...
55-
def __pos__(self): ...
56-
def __abs__(self): ...
57-
def total_seconds(self) -> int: ...
58-
def to_pytimedelta(self) -> Sequence[timedelta]: ...
59-
days: int = ...
60-
seconds: int = ...
61-
microseconds: int = ...
62-
nanoseconds: int = ...
63-
@property
64-
def components(self) -> int: ...
36+
dtype: np.dtype | ExtensionDtype | None = None,
37+
copy: bool = True,
38+
) -> TimedeltaArray: ...

pandas-stubs/core/construction.pyi

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
from collections.abc import Sequence
2-
from typing import overload
2+
from typing import (
3+
Any,
4+
overload,
5+
)
36

47
import numpy as np
58
from pandas.core.arrays.base import ExtensionArray
69
from pandas.core.arrays.boolean import BooleanArray
10+
from pandas.core.arrays.datetimes import DatetimeArray
711
from pandas.core.arrays.floating import FloatingArray
812
from pandas.core.arrays.integer import IntegerArray
13+
from pandas.core.arrays.numpy_ import NumpyExtensionArray
14+
from pandas.core.arrays.timedeltas import TimedeltaArray
15+
from pandas.core.indexes.base import Index
16+
from pandas.core.indexes.datetimes import DatetimeIndex
17+
from pandas.core.indexes.range import RangeIndex
18+
from pandas.core.indexes.timedeltas import TimedeltaIndex
19+
from pandas.core.series import Series
920

1021
from pandas._libs.missing import NAType
22+
from pandas._libs.tslibs.nattype import NaTType
23+
from pandas._libs.tslibs.timedeltas import Timedelta
24+
from pandas._libs.tslibs.timestamps import Timestamp
1125
from pandas._typing import (
12-
PandasBooleanDtypeArg,
13-
PandasFloatDtypeArg,
14-
PandasIntDtypeArg,
15-
PandasUIntDtypeArg,
26+
np_ndarray,
1627
np_ndarray_anyint,
1728
np_ndarray_bool,
29+
np_ndarray_dt,
1830
np_ndarray_float,
31+
np_ndarray_td,
1932
)
2033

2134
from pandas.core.dtypes.dtypes import ExtensionDtype
@@ -27,22 +40,75 @@ def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlapping
2740
copy: bool = True,
2841
) -> BooleanArray: ...
2942
@overload
43+
def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
44+
data: Sequence[NAType | None],
45+
dtype: str | np.dtype | ExtensionDtype | None = None,
46+
copy: bool = True,
47+
) -> NumpyExtensionArray: ...
48+
@overload
49+
def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
50+
data: (
51+
Sequence[bool | np.bool | NAType | None]
52+
| np_ndarray_bool
53+
| BooleanArray
54+
| Index[bool]
55+
| Series[int]
56+
),
57+
dtype: str | np.dtype | ExtensionDtype | None = None,
58+
copy: bool = True,
59+
) -> BooleanArray: ...
60+
@overload
3061
def array( # type: ignore[overload-overlap]
31-
data: Sequence[int | np.integer | NAType | None] | np_ndarray_anyint | IntegerArray,
32-
dtype: PandasIntDtypeArg | PandasUIntDtypeArg | None = None,
62+
data: (
63+
Sequence[int | np.integer | NAType | None]
64+
| np_ndarray_anyint
65+
| IntegerArray
66+
| Index[int]
67+
| RangeIndex
68+
| Series[int]
69+
),
70+
dtype: str | np.dtype | ExtensionDtype | None = None,
3371
copy: bool = True,
3472
) -> IntegerArray: ...
3573
@overload
36-
def array(
74+
def array( # type: ignore[overload-overlap]
3775
data: (
38-
Sequence[float | np.floating | NAType | None] | np_ndarray_float | FloatingArray
76+
Sequence[float | np.floating | NAType | None]
77+
| np_ndarray_float
78+
| FloatingArray
79+
| Index[float]
80+
| Series[float]
3981
),
40-
dtype: PandasFloatDtypeArg | None = None,
82+
dtype: str | np.dtype | ExtensionDtype | None = None,
4183
copy: bool = True,
4284
) -> FloatingArray: ...
4385
@overload
86+
def array( # type: ignore[overload-overlap]
87+
data: (
88+
Sequence[Timestamp | np.datetime64 | NaTType | None]
89+
| np_ndarray_dt
90+
| DatetimeArray
91+
| DatetimeIndex
92+
| Series[Timestamp]
93+
),
94+
dtype: str | np.dtype | ExtensionDtype | None = None,
95+
copy: bool = True,
96+
) -> DatetimeArray: ...
97+
@overload
98+
def array( # type: ignore[overload-overlap]
99+
data: (
100+
Sequence[Timedelta | np.timedelta64 | NaTType | None]
101+
| np_ndarray_td
102+
| TimedeltaArray
103+
| TimedeltaIndex
104+
| Series[Timedelta]
105+
),
106+
dtype: str | np.dtype | ExtensionDtype | None = None,
107+
copy: bool = True,
108+
) -> TimedeltaArray: ...
109+
@overload
44110
def array(
45-
data: Sequence[object],
111+
data: Sequence[Any] | np_ndarray | ExtensionArray | Index | Series,
46112
dtype: str | np.dtype | ExtensionDtype | None = None,
47113
copy: bool = True,
48-
) -> ExtensionArray: ...
114+
) -> NumpyExtensionArray: ...

tests/arrays/test_arrays.py

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import numpy as np
2+
import pandas as pd
3+
from pandas.core.arrays.boolean import BooleanArray
4+
from typing_extensions import assert_type
5+
6+
from tests import check
7+
8+
9+
def test_construction() -> None:
10+
check(assert_type(pd.array([True]), BooleanArray), BooleanArray)
11+
check(assert_type(pd.array([True, np.bool(True)]), BooleanArray), BooleanArray)
12+
check(assert_type(pd.array([True, None]), BooleanArray), BooleanArray)
13+
check(assert_type(pd.array([True, pd.NA]), BooleanArray), BooleanArray)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import numpy as np
2+
import pandas as pd
3+
from pandas.core.arrays.integer import IntegerArray
4+
from typing_extensions import assert_type
5+
6+
from tests import check
7+
8+
9+
def test_construction() -> None:
10+
check(assert_type(pd.array([1]), IntegerArray), IntegerArray)
11+
check(assert_type(pd.array([1, np.int64(1)]), IntegerArray), IntegerArray)
12+
check(assert_type(pd.array([1, None]), IntegerArray), IntegerArray)
13+
check(assert_type(pd.array([1, pd.NA, None]), IntegerArray), IntegerArray)

0 commit comments

Comments
 (0)