Skip to content

Commit 74f2b5a

Browse files
authored
CLEAN: remove nonpublic stubs (#170)
* CLEAN: remove nonpublic stubs * put back pd.value_counts()
1 parent 6525678 commit 74f2b5a

File tree

6 files changed

+117
-239
lines changed

6 files changed

+117
-239
lines changed

pandas-stubs/api/extensions/__init__.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from pandas.core.accessor import (
33
register_index_accessor as register_index_accessor,
44
register_series_accessor as register_series_accessor,
55
)
6-
from pandas.core.algorithms import take as take
76
from pandas.core.arrays import (
87
ExtensionArray as ExtensionArray,
98
ExtensionScalarOpsMixin as ExtensionScalarOpsMixin,

pandas-stubs/core/algorithms.pyi

+27-61
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,40 @@
1-
from typing import Any
1+
from typing import (
2+
Any,
3+
overload,
4+
)
25

36
import numpy as np
4-
from pandas.core.indexes.base import Index
5-
6-
def unique(values): ...
7-
8-
unique1d = unique
9-
10-
def isin(comps, values) -> np.ndarray: ...
7+
from pandas import (
8+
Categorical,
9+
Index,
10+
Series,
11+
)
12+
from pandas.api.extensions import ExtensionArray
13+
14+
from pandas._typing import AnyArrayLike
15+
16+
@overload
17+
def unique(values: Index) -> Index: ...
18+
@overload
19+
def unique(values: Categorical) -> Categorical: ...
20+
@overload
21+
def unique(values: Series) -> np.ndarray | ExtensionArray: ...
22+
@overload
23+
def unique(values: np.ndarray | list) -> np.ndarray: ...
24+
@overload
25+
def unique(values: ExtensionArray) -> ExtensionArray: ...
1126
def factorize(
1227
values: Any,
1328
sort: bool = ...,
14-
na_sentinel: int = ...,
29+
na_sentinel: int | None = ...,
30+
use_na_sentinel: bool = ...,
1531
size_hint: int | None = ...,
1632
) -> tuple[np.ndarray, np.ndarray | Index]: ...
1733
def value_counts(
18-
values,
34+
values: AnyArrayLike | list | tuple,
1935
sort: bool = ...,
2036
ascending: bool = ...,
2137
normalize: bool = ...,
22-
bins=...,
38+
bins: int | None = ...,
2339
dropna: bool = ...,
2440
) -> Series: ...
25-
def duplicated(values, keep=...) -> np.ndarray: ...
26-
def mode(values, dropna: bool = ...) -> Series: ...
27-
def rank(
28-
values,
29-
axis: int = ...,
30-
method: str = ...,
31-
na_option: str = ...,
32-
ascending: bool = ...,
33-
pct: bool = ...,
34-
): ...
35-
def checked_add_with_arr(arr, b, arr_mask=..., b_mask=...): ...
36-
def quantile(x, q, interpolation_method: str = ...): ...
37-
38-
class SelectN:
39-
obj = ...
40-
n = ...
41-
keep = ...
42-
def __init__(self, obj, n: int, keep: str) -> None: ...
43-
def nlargest(self): ...
44-
def nsmallest(self): ...
45-
@staticmethod
46-
def is_valid_dtype_n_method(dtype) -> bool: ...
47-
48-
class SelectNSeries(SelectN):
49-
def compute(self, method): ...
50-
51-
class SelectNFrame(SelectN):
52-
columns = ...
53-
def __init__(self, obj, n: int, keep: str, columns) -> None: ...
54-
def compute(self, method): ...
55-
56-
def take(arr, indices, axis: int = ..., allow_fill: bool = ..., fill_value=...): ...
57-
def take_nd(
58-
arr, indexer, axis: int = ..., out=..., fill_value=..., allow_fill: bool = ...
59-
): ...
60-
61-
take_1d = take_nd
62-
63-
def take_2d_multi(arr, indexer, fill_value=...): ...
64-
def searchsorted(arr, value, side: str = ..., sorter=...): ...
65-
def diff(arr, n: int, axis: int = ..., stacklevel=...): ...
66-
def safe_sort(
67-
values,
68-
codes=...,
69-
na_sentinel: int = ...,
70-
assume_unique: bool = ...,
71-
verify: bool = ...,
72-
) -> np.ndarray | tuple[np.ndarray, np.ndarray]: ...
73-
74-
from pandas import Series

pandas-stubs/core/apply.pyi

-101
This file was deleted.

pandas-stubs/core/nanops.pyi

-46
This file was deleted.

pandas-stubs/core/sorting.pyi

-30
This file was deleted.

tests/test_pandas.py

+90
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
from typing import (
55
TYPE_CHECKING,
66
Any,
7+
Union,
78
)
89

910
import numpy as np
1011
import pandas as pd
12+
from pandas.api.extensions import ExtensionArray
1113
import pytest
1214
from typing_extensions import assert_type
1315

@@ -181,3 +183,91 @@ def test_read_xml() -> None:
181183
),
182184
pd.DataFrame,
183185
)
186+
187+
188+
def test_unique() -> None:
189+
# Taken from the docs
190+
check(
191+
assert_type(
192+
pd.unique(pd.Series([2, 1, 3, 3])), Union[np.ndarray, ExtensionArray]
193+
),
194+
np.ndarray,
195+
)
196+
197+
check(
198+
assert_type(
199+
pd.unique(pd.Series([2] + [1] * 5)), Union[np.ndarray, ExtensionArray]
200+
),
201+
np.ndarray,
202+
)
203+
204+
check(
205+
assert_type(
206+
pd.unique(pd.Series([pd.Timestamp("20160101"), pd.Timestamp("20160101")])),
207+
Union[np.ndarray, ExtensionArray],
208+
),
209+
np.ndarray,
210+
)
211+
212+
check(
213+
assert_type(
214+
pd.unique(
215+
pd.Series(
216+
[
217+
pd.Timestamp("20160101", tz="US/Eastern"),
218+
pd.Timestamp("20160101", tz="US/Eastern"),
219+
]
220+
)
221+
),
222+
Union[np.ndarray, ExtensionArray],
223+
),
224+
pd.arrays.DatetimeArray,
225+
)
226+
check(
227+
assert_type(
228+
pd.unique(
229+
pd.Index(
230+
[
231+
pd.Timestamp("20160101", tz="US/Eastern"),
232+
pd.Timestamp("20160101", tz="US/Eastern"),
233+
]
234+
)
235+
),
236+
pd.Index,
237+
),
238+
pd.DatetimeIndex,
239+
)
240+
241+
check(assert_type(pd.unique(list("baabc")), np.ndarray), np.ndarray)
242+
243+
check(
244+
assert_type(
245+
pd.unique(pd.Series(pd.Categorical(list("baabc")))),
246+
Union[np.ndarray, ExtensionArray],
247+
),
248+
pd.Categorical,
249+
)
250+
check(
251+
assert_type(
252+
pd.unique(pd.Series(pd.Categorical(list("baabc"), categories=list("abc")))),
253+
Union[np.ndarray, ExtensionArray],
254+
),
255+
pd.Categorical,
256+
)
257+
check(
258+
assert_type(
259+
pd.unique(
260+
pd.Series(
261+
pd.Categorical(list("baabc"), categories=list("abc"), ordered=True)
262+
)
263+
),
264+
Union[np.ndarray, ExtensionArray],
265+
),
266+
pd.Categorical,
267+
)
268+
check(
269+
assert_type(
270+
pd.unique([("a", "b"), ("b", "a"), ("a", "c"), ("b", "a")]), np.ndarray
271+
),
272+
np.ndarray,
273+
)

0 commit comments

Comments
 (0)