Skip to content

Commit 5067713

Browse files
committed
enable reportUnknownVariableType
1 parent 0923f15 commit 5067713

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+716
-682
lines changed

pandas-stubs/__init__.pyi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ from pandas.core.api import (
4747
UInt16Dtype as UInt16Dtype,
4848
UInt32Dtype as UInt32Dtype,
4949
UInt64Dtype as UInt64Dtype,
50-
array as array,
5150
bdate_range as bdate_range,
5251
date_range as date_range,
5352
factorize as factorize,
@@ -66,6 +65,7 @@ from pandas.core.api import (
6665
)
6766
from pandas.core.arrays.sparse import SparseDtype as SparseDtype
6867
from pandas.core.computation.api import eval as eval
68+
from pandas.core.construction import array as array
6969
from pandas.core.reshape.api import (
7070
concat as concat,
7171
crosstab as crosstab,
@@ -100,13 +100,11 @@ from pandas.io.api import (
100100
HDFStore as HDFStore,
101101
read_clipboard as read_clipboard,
102102
read_csv as read_csv,
103-
read_excel as read_excel,
104103
read_feather as read_feather,
105104
read_fwf as read_fwf,
106105
read_hdf as read_hdf,
107106
read_html as read_html,
108107
read_json as read_json,
109-
read_orc as read_orc,
110108
read_parquet as read_parquet,
111109
read_pickle as read_pickle,
112110
read_sas as read_sas,
@@ -118,6 +116,12 @@ from pandas.io.api import (
118116
read_table as read_table,
119117
read_xml as read_xml,
120118
)
119+
from pandas.io.api import (
120+
read_excel as read_excel, # pyright: ignore[reportUnknownVariableType]
121+
)
122+
from pandas.io.api import (
123+
read_orc as read_orc, # pyright: ignore[reportUnknownVariableType]
124+
)
121125
from pandas.io.json._normalize import json_normalize as json_normalize
122126
from pandas.tseries import offsets as offsets
123127
from pandas.tseries.api import infer_freq as infer_freq

pandas-stubs/core/frame.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
10831083
@overload
10841084
def sort_values(
10851085
self,
1086-
by: _str | Sequence[_str],
1086+
by: _str | SequenceNotStr[_str],
10871087
*,
10881088
axis: Axis = 0,
10891089
ascending: _bool | Sequence[_bool] = ...,
@@ -1096,7 +1096,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
10961096
@overload
10971097
def sort_values(
10981098
self,
1099-
by: _str | Sequence[_str],
1099+
by: _str | SequenceNotStr[_str],
11001100
*,
11011101
axis: Axis = 0,
11021102
ascending: _bool | Sequence[_bool] = ...,
@@ -1303,7 +1303,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13031303
@overload
13041304
def groupby( # type: ignore[overload-overlap] # pyright: ignore reportOverlappingOverload
13051305
self,
1306-
by: MultiIndex | GroupByObjectNonScalar | None = ...,
1306+
by: MultiIndex | GroupByObjectNonScalar[Any] | None = ...,
13071307
level: IndexLabel | None = ...,
13081308
as_index: Literal[True] = True,
13091309
sort: _bool = ...,
@@ -1314,7 +1314,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13141314
@overload
13151315
def groupby( # type: ignore[overload-overlap]
13161316
self,
1317-
by: MultiIndex | GroupByObjectNonScalar | None = ...,
1317+
by: MultiIndex | GroupByObjectNonScalar[Any] | None = ...,
13181318
level: IndexLabel | None = ...,
13191319
as_index: Literal[False] = False,
13201320
sort: _bool = ...,

pandas-stubs/io/api.pyi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ from pandas.io.clipboards import read_clipboard as read_clipboard
22
from pandas.io.excel import (
33
ExcelFile as ExcelFile,
44
ExcelWriter as ExcelWriter,
5-
read_excel as read_excel,
5+
)
6+
from pandas.io.excel import (
7+
read_excel as read_excel, # pyright: ignore[reportUnknownVariableType]
68
)
79
from pandas.io.feather_format import read_feather as read_feather
810
from pandas.io.html import read_html as read_html
911
from pandas.io.json import read_json as read_json
10-
from pandas.io.orc import read_orc as read_orc
12+
from pandas.io.orc import (
13+
read_orc as read_orc, # pyright: ignore[reportUnknownVariableType]
14+
)
1115
from pandas.io.parquet import read_parquet as read_parquet
12-
from pandas.io.parsers import (
16+
from pandas.io.parsers.readers import (
1317
read_csv as read_csv,
1418
read_fwf as read_fwf,
1519
read_table as read_table,

pandas-stubs/io/clipboards.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def read_clipboard(
3535
header: int | Sequence[int] | Literal["infer"] | None = ...,
3636
names: ListLikeHashable | None = ...,
3737
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
38-
usecols: UsecolsArgType = ...,
38+
usecols: UsecolsArgType[Any] = ...,
3939
dtype: DtypeArg | defaultdict[Any, Any] | None = ...,
4040
engine: CSVEngine | None = ...,
4141
converters: dict[int | str, Callable[[str], Any]] = ...,
@@ -94,7 +94,7 @@ def read_clipboard(
9494
header: int | Sequence[int] | Literal["infer"] | None = ...,
9595
names: ListLikeHashable | None = ...,
9696
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
97-
usecols: UsecolsArgType = ...,
97+
usecols: UsecolsArgType[Any] = ...,
9898
dtype: DtypeArg | defaultdict[Any, Any] | None = ...,
9999
engine: CSVEngine | None = ...,
100100
converters: dict[int | str, Callable[[str], Any]] = ...,
@@ -153,7 +153,7 @@ def read_clipboard(
153153
header: int | Sequence[int] | Literal["infer"] | None = ...,
154154
names: ListLikeHashable | None = ...,
155155
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
156-
usecols: UsecolsArgType = ...,
156+
usecols: UsecolsArgType[Any] = ...,
157157
dtype: DtypeArg | defaultdict[Any, Any] | None = ...,
158158
engine: CSVEngine | None = ...,
159159
converters: dict[int | str, Callable[[str], Any]] = ...,

pandas-stubs/io/excel/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pandas.io.excel._base import (
22
ExcelFile as ExcelFile,
33
ExcelWriter as ExcelWriter,
4-
read_excel as read_excel,
4+
)
5+
from pandas.io.excel._base import (
6+
read_excel as read_excel, # pyright: ignore[reportUnknownVariableType]
57
)

pandas-stubs/io/excel/_base.pyi

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ from typing import (
1515
overload,
1616
)
1717

18-
from odf.opendocument import OpenDocument # pyright: ignore[reportMissingTypeStubs]
1918
from openpyxl.workbook.workbook import Workbook
2019
from pandas.core.frame import DataFrame
2120
import pyxlsb.workbook # pyright: ignore[reportMissingTypeStubs]
@@ -43,6 +42,10 @@ from pandas._typing import (
4342
UsecolsArgType,
4443
)
4544

45+
from odf.opendocument import ( # pyright: ignore[reportMissingTypeStubs] # isort: skip
46+
OpenDocument, # pyright: ignore[reportUnknownVariableType]
47+
)
48+
4649
@overload
4750
def read_excel(
4851
io: (
@@ -59,7 +62,7 @@ def read_excel(
5962
header: int | Sequence[int] | None = ...,
6063
names: ListLikeHashable | None = ...,
6164
index_col: int | Sequence[int] | str | None = ...,
62-
usecols: str | UsecolsArgType = ...,
65+
usecols: str | UsecolsArgType[Any] = ...,
6366
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
6467
engine: ExcelReadEngine | None = ...,
6568
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
@@ -102,7 +105,7 @@ def read_excel(
102105
header: int | Sequence[int] | None = ...,
103106
names: ListLikeHashable | None = ...,
104107
index_col: int | Sequence[int] | str | None = ...,
105-
usecols: str | UsecolsArgType = ...,
108+
usecols: str | UsecolsArgType[Any] = ...,
106109
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
107110
engine: ExcelReadEngine | None = ...,
108111
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
@@ -146,7 +149,7 @@ def read_excel( # type: ignore[overload-cannot-match]
146149
header: int | Sequence[int] | None = ...,
147150
names: ListLikeHashable | None = ...,
148151
index_col: int | Sequence[int] | str | None = ...,
149-
usecols: str | UsecolsArgType = ...,
152+
usecols: str | UsecolsArgType[Any] = ...,
150153
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
151154
engine: ExcelReadEngine | None = ...,
152155
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
@@ -189,7 +192,7 @@ def read_excel(
189192
header: int | Sequence[int] | None = ...,
190193
names: ListLikeHashable | None = ...,
191194
index_col: int | Sequence[int] | str | None = ...,
192-
usecols: str | UsecolsArgType = ...,
195+
usecols: str | UsecolsArgType[Any] = ...,
193196
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
194197
engine: ExcelReadEngine | None = ...,
195198
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
@@ -312,7 +315,7 @@ class ExcelFile:
312315
header: int | Sequence[int] | None = ...,
313316
names: ListLikeHashable | None = ...,
314317
index_col: int | Sequence[int] | None = ...,
315-
usecols: str | UsecolsArgType = ...,
318+
usecols: str | UsecolsArgType[Any] = ...,
316319
converters: dict[int | str, Callable[[Any], Any]] | None = ...,
317320
true_values: Iterable[Hashable] | None = ...,
318321
false_values: Iterable[Hashable] | None = ...,
@@ -340,7 +343,7 @@ class ExcelFile:
340343
header: int | Sequence[int] | None = ...,
341344
names: ListLikeHashable | None = ...,
342345
index_col: int | Sequence[int] | None = ...,
343-
usecols: str | UsecolsArgType = ...,
346+
usecols: str | UsecolsArgType[Any] = ...,
344347
converters: dict[int | str, Callable[[Any], Any]] | None = ...,
345348
true_values: Iterable[Hashable] | None = ...,
346349
false_values: Iterable[Hashable] | None = ...,

pandas-stubs/io/orc.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Any
22

3-
from fsspec.spec import AbstractFileSystem # pyright: ignore[reportMissingTypeStubs]
43
from pandas import DataFrame
54
from pyarrow.fs import FileSystem
65

@@ -12,6 +11,10 @@ from pandas._typing import (
1211
ReadBuffer,
1312
)
1413

14+
from fsspec.spec import ( # pyright: ignore[reportMissingTypeStubs] # isort: skip
15+
AbstractFileSystem, # pyright: ignore[reportUnknownVariableType]
16+
)
17+
1518
def read_orc(
1619
path: FilePath | ReadBuffer[bytes],
1720
columns: list[HashableT] | None = None,

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ reportUnknownArgumentType = false
303303
reportUnknownLambdaType = false
304304
reportUnknownMemberType = false
305305
reportUnknownParameterType = false
306-
reportUnknownVariableType = false
307306
reportPrivateUsage = false
308307
# enable optional checks
309308
reportMissingModuleSource = true

tests/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,19 @@ def check(
135135
if dtype is None:
136136
return actual
137137

138+
value: Any
138139
if isinstance(actual, pd.Series):
139-
value = actual.iloc[index_to_check_for_type]
140+
value = actual.iloc[ # pyright: ignore[reportUnknownVariableType]
141+
index_to_check_for_type
142+
]
140143
elif isinstance(actual, pd.Index):
141-
value = actual[index_to_check_for_type]
144+
value = actual[ # pyright: ignore[reportUnknownVariableType]
145+
index_to_check_for_type
146+
]
142147
elif isinstance(actual, BaseGroupBy):
143-
value = actual.obj # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
148+
value = actual.obj # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportUnknownVariableType]
144149
elif hasattr(actual, "__iter__"):
145-
value = next(
150+
value = next( # pyright: ignore[reportUnknownVariableType]
146151
iter(actual) # pyright: ignore[reportArgumentType,reportCallIssue]
147152
)
148153
else:
@@ -151,7 +156,7 @@ def check(
151156

152157
if not isinstance(value, dtype):
153158
raise RuntimeError(f"Expected type '{dtype}' but got '{type(value)}'")
154-
return actual
159+
return actual # pyright: ignore[reportUnknownVariableType]
155160

156161

157162
def pytest_warns_bounded(
@@ -161,7 +166,7 @@ def pytest_warns_bounded(
161166
upper: str | None = None,
162167
version_str: str | None = None,
163168
upper_exception: type[Exception] | None = None,
164-
) -> AbstractContextManager[Any]:
169+
) -> AbstractContextManager[Any, bool | None]:
165170
"""
166171
Version conditional pytest.warns context manager
167172

tests/arrays/test_extension_array.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Test common ExtensionArray methods
2+
23
import numpy as np
34
import pandas as pd
45
from pandas.core.arrays import ExtensionArray

0 commit comments

Comments
 (0)