Skip to content

Commit cc7f48f

Browse files
TYP: Drop ANN ignores from certain files in arrays (#1583)
* Drop ANN ignores from certain files in arrays * GH1583 PR Feedback * PR Feedback * Fix test * Fix PR * Fix PR * Fix PR
1 parent a0f310e commit cc7f48f

File tree

6 files changed

+75
-17
lines changed

6 files changed

+75
-17
lines changed

pandas-stubs/core/arrays/integer.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from pandas.core.arrays.masked import BaseMaskedArray
22

33
from pandas._libs.missing import NAType
4+
from pandas._typing import (
5+
AnyArrayLike,
6+
np_ndarray_bool,
7+
)
48

59
from pandas.core.dtypes.base import ExtensionDtype as ExtensionDtype
610

@@ -16,8 +20,12 @@ class _IntegerDtype(ExtensionDtype):
1620
class IntegerArray(BaseMaskedArray):
1721
@property
1822
def dtype(self) -> _IntegerDtype: ...
19-
def __init__(self, values, mask, copy: bool = ...) -> None: ...
20-
def __setitem__(self, key, value) -> None: ...
23+
def __init__(
24+
self,
25+
values: AnyArrayLike,
26+
mask: np_ndarray_bool,
27+
copy: bool = False,
28+
) -> None: ...
2129

2230
class Int8Dtype(_IntegerDtype): ...
2331
class Int16Dtype(_IntegerDtype): ...

pandas-stubs/core/arrays/masked.pyi

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
from collections.abc import Iterator
12
from typing import (
23
Any,
34
overload,
45
)
56

67
from pandas.core.arrays import ExtensionArray as ExtensionArray
8+
from pandas.core.series import Series
79
from typing_extensions import Self
810

911
from pandas._typing import (
12+
DtypeArg,
1013
NpDtype,
1114
Scalar,
1215
ScalarIndexer,
1316
SequenceIndexer,
1417
np_1darray,
18+
np_1darray_bool,
1519
npt,
1620
)
1721

@@ -20,8 +24,8 @@ class BaseMaskedArray(ExtensionArray):
2024
def __getitem__(self, item: ScalarIndexer) -> Any: ...
2125
@overload
2226
def __getitem__(self, item: SequenceIndexer) -> Self: ...
23-
def __iter__(self): ...
24-
def __invert__(self): ...
27+
def __iter__(self) -> Iterator[Any]: ...
28+
def __invert__(self) -> Self: ...
2529
def to_numpy(
2630
self,
2731
dtype: npt.DTypeLike | None = ...,
@@ -32,9 +36,9 @@ class BaseMaskedArray(ExtensionArray):
3236
def __array__(
3337
self, dtype: NpDtype | None = None, copy: bool | None = None
3438
) -> np_1darray: ...
35-
def __arrow_array__(self, type=...): ...
36-
def isna(self): ...
39+
def __arrow_array__(self, type: DtypeArg | None = None) -> Any: ...
40+
def copy(self) -> Self: ...
41+
def value_counts(self, dropna: bool = True) -> Series[int]: ...
42+
def isna(self) -> np_1darray_bool: ...
3743
@property
3844
def nbytes(self) -> int: ...
39-
def copy(self): ...
40-
def value_counts(self, dropna: bool = True): ...
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
from typing import Literal
1+
from typing import (
2+
Any,
3+
Literal,
4+
)
25

36
from pandas.core.arrays import PandasArray
7+
from pandas.core.series import Series
48

59
from pandas._libs.missing import NAType
10+
from pandas._typing import (
11+
AnyArrayLike,
12+
DtypeArg,
13+
)
614

715
from pandas.core.dtypes.base import ExtensionDtype
816

@@ -12,7 +20,7 @@ class StringDtype(ExtensionDtype):
1220
def na_value(self) -> NAType: ...
1321

1422
class StringArray(PandasArray):
15-
def __init__(self, values, copy: bool = ...) -> None: ...
16-
def __arrow_array__(self, type=...): ...
17-
def __setitem__(self, key, value) -> None: ...
18-
def value_counts(self, dropna: bool = True): ...
23+
def __init__(self, values: AnyArrayLike, copy: bool = False) -> None: ...
24+
def __arrow_array__(self, type: DtypeArg | None = None) -> Any: ...
25+
def __setitem__(self, key: Any, value: Any) -> None: ...
26+
def value_counts(self, dropna: bool = True) -> Series[int]: ...

pandas-stubs/io/excel/_base.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class ExcelFile:
304304
storage_options: StorageOptions = ...,
305305
engine_kwargs: dict[str, Any] | None = ...,
306306
) -> None: ...
307-
def __fspath__(self): ...
307+
def __fspath__(self) -> str: ...
308308
@overload
309309
def parse(
310310
self,

pyproject.toml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,39 @@ ignore = [
209209
# TODO: remove when window is fully typed
210210
"ANN001", "ANN201", "ANN204", "ANN206",
211211
]
212-
"*array*" = [
212+
"*arrays/sparse/*" = [
213213
# TODO: remove when array is fully typed
214214
"ANN001", "ANN201", "ANN204", "ANN206",
215215
]
216-
"*excel/_base.pyi" = [
217-
# TODO: remove when excel/_base.pyi is fully typed
216+
"*arrays/boolean.pyi" = [
217+
# TODO: remove when boolean array is fully typed
218218
"ANN001", "ANN201", "ANN204", "ANN206",
219219
]
220+
"*arrays/categorical.pyi" = [
221+
# TODO: remove when categorical array is fully typed
222+
"ANN001", "ANN201", "ANN204", "ANN206",
223+
]
224+
"*arrays/datetimelike.pyi" = [
225+
# TODO: remove when array is fully typed
226+
"ANN001", "ANN201", "ANN204", "ANN206",
227+
]
228+
"*arrays/datetimes.pyi" = [
229+
# TODO: remove when datetime array is fully typed
230+
"ANN001", "ANN201", "ANN204", "ANN206",
231+
]
232+
"*arrays/interval.pyi" = [
233+
# TODO: remove when interval array is fully typed
234+
"ANN001", "ANN201", "ANN204", "ANN206",
235+
]
236+
"*arrays/period.pyi" = [
237+
# TODO: remove when period array is fully typed
238+
"ANN001", "ANN201", "ANN204", "ANN206",
239+
]
240+
"*arrays/timedeltas.pyi" = [
241+
# TODO: remove when timedelta array is fully typed
242+
"ANN001", "ANN201", "ANN204", "ANN206",
243+
]
244+
220245
"scripts/*" = [
221246
# The following rules are ignored permanently for good reasons
222247
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em

tests/test_io.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import csv
44
from functools import partial
55
import io
6+
import os
67
import pathlib
78
from pathlib import Path
89
import sqlite3
@@ -1156,6 +1157,18 @@ def test_excel_reader() -> None:
11561157
check(assert_type(pd.read_excel(ef), pd.DataFrame), pd.DataFrame)
11571158

11581159

1160+
def test_excel_fspath() -> None:
1161+
"""Test ExcelFile.__fspath__ type."""
1162+
with ensure_clean(".xlsx") as path:
1163+
check(assert_type(DF.to_excel(path), None), type(None))
1164+
with pd.ExcelFile(
1165+
path_or_buffer=path,
1166+
engine="openpyxl",
1167+
engine_kwargs={"data_only": True},
1168+
) as ef:
1169+
check(assert_type(os.fspath(ef), str), str)
1170+
1171+
11591172
def test_excel_writer() -> None:
11601173
with ensure_clean(".xlsx") as path:
11611174
with pd.ExcelWriter(path) as ew:

0 commit comments

Comments
 (0)