Skip to content

Commit a21542d

Browse files
committed
enable reportUnknownArgumentType
1 parent 0923f15 commit a21542d

File tree

15 files changed

+149
-62
lines changed

15 files changed

+149
-62
lines changed

pandas-stubs/core/dtypes/missing.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ def notna(obj: np_ndarray[ShapeT]) -> np_ndarray[ShapeT, np.bool]: ...
5454
@overload
5555
def notna(obj: list[Any]) -> np_ndarray_bool: ...
5656
@overload
57-
def notna(obj: ScalarT | NaTType | NAType | None) -> TypeIs[ScalarT]: ...
57+
def notna(obj: Scalar | NaTType | NAType | None) -> TypeIs[Scalar]: ...
5858

5959
notnull = notna

pandas-stubs/errors/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ class InvalidColumnName(Warning): ...
4848
class CategoricalConversionWarning(Warning): ...
4949
class InvalidVersion(ValueError): ...
5050
class NoBufferPresent(Exception): ...
51+
class Pandas4Warning(Warning): ...

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ enableTypeIgnoreComments = false # use pyright-specific ignores
299299
# disable subset of strict
300300
reportMissingParameterType = false
301301
reportUnnecessaryTypeIgnoreComment = true
302-
reportUnknownArgumentType = false
303302
reportUnknownLambdaType = false
304303
reportUnknownMemberType = false
305304
reportUnknownParameterType = false

tests/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from collections.abc import Iterable
34
from contextlib import (
45
AbstractContextManager,
56
nullcontext,
@@ -11,6 +12,7 @@
1112
Any,
1213
Final,
1314
Literal,
15+
cast,
1416
get_args,
1517
get_origin,
1618
)
@@ -140,17 +142,17 @@ def check(
140142
elif isinstance(actual, pd.Index):
141143
value = actual[index_to_check_for_type]
142144
elif isinstance(actual, BaseGroupBy):
143-
value = actual.obj # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
144-
elif hasattr(actual, "__iter__"):
145-
value = next(
146-
iter(actual) # pyright: ignore[reportArgumentType,reportCallIssue]
147-
)
145+
value = actual.obj # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
146+
elif isinstance(actual, Iterable):
147+
value = next(iter(cast("Iterable[Any]", actual)))
148148
else:
149149
assert hasattr(actual, attr)
150150
value = getattr(actual, attr)
151151

152152
if not isinstance(value, dtype):
153-
raise RuntimeError(f"Expected type '{dtype}' but got '{type(value)}'")
153+
raise RuntimeError(
154+
f"Expected type '{dtype}' but got '{type(value)}'" # pyright: ignore[reportUnknownArgumentType]
155+
)
154156
return actual
155157

156158

tests/extension/decimal/array.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from pandas._typing import (
3636
ArrayLike,
3737
AstypeArg,
38+
Dtype,
3839
ListLike,
3940
ScalarIndexer,
4041
SequenceIndexer,
@@ -199,8 +200,11 @@ def reconstruct(
199200
return DecimalArray._from_sequence(x)
200201

201202
if ufunc.nout > 1:
202-
return tuple(reconstruct(x) for x in result)
203-
return reconstruct(result)
203+
return tuple(
204+
reconstruct(x) # pyright: ignore[reportUnknownArgumentType]
205+
for x in result
206+
)
207+
return reconstruct(result) # pyright: ignore[reportUnknownArgumentType]
204208

205209
def __getitem__(self, item: ScalarIndexer | SequenceIndexer) -> Any:
206210
if isinstance(item, numbers.Integral):
@@ -241,7 +245,7 @@ def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ..
241245
@overload
242246
def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike: ...
243247

244-
def astype(self, dtype, copy=True):
248+
def astype(self, dtype: Dtype, copy: bool = True):
245249
if is_dtype_equal(dtype, self._dtype):
246250
if not copy:
247251
return self

tests/frame/test_frame.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
_PandasNamedTuple: TypeAlias = tuple
7777

7878
if not PD_LTE_23:
79-
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip
79+
from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration]
8080
else:
8181
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]
8282

@@ -310,7 +310,13 @@ def my_named_func_2(df: pd.DataFrame) -> pd.Series:
310310
check(assert_type(df.assign(c=df["a"].index), pd.DataFrame), pd.DataFrame)
311311
check(assert_type(df.assign(c=df["a"].to_numpy()), pd.DataFrame), pd.DataFrame)
312312
check(assert_type(df.assign(c=2), pd.DataFrame), pd.DataFrame)
313-
check(assert_type(df.assign(c=my_unnamed_func), pd.DataFrame), pd.DataFrame)
313+
check(
314+
assert_type(
315+
df.assign(c=my_unnamed_func), # pyright: ignore[reportUnknownArgumentType]
316+
pd.DataFrame,
317+
),
318+
pd.DataFrame,
319+
)
314320
check(assert_type(df.assign(c=my_named_func_1), pd.DataFrame), pd.DataFrame)
315321
check(assert_type(df.assign(c=my_named_func_2), pd.DataFrame), pd.DataFrame)
316322
check(assert_type(df.assign(c=None), pd.DataFrame), pd.DataFrame)
@@ -1367,7 +1373,13 @@ def gethead(s: pd.Series, y: int) -> pd.Series:
13671373
def test_types_map() -> None:
13681374
# GH774
13691375
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
1370-
check(assert_type(df.map(lambda x: x**2), pd.DataFrame), pd.DataFrame)
1376+
check(
1377+
assert_type(
1378+
df.map(lambda x: x**2), # pyright: ignore[reportUnknownArgumentType]
1379+
pd.DataFrame,
1380+
),
1381+
pd.DataFrame,
1382+
)
13711383
check(assert_type(df.map(np.exp), pd.DataFrame), pd.DataFrame)
13721384
check(assert_type(df.map(str), pd.DataFrame), pd.DataFrame)
13731385
# na_action parameter was added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
@@ -2315,8 +2327,8 @@ def test_types_rename_axis() -> None:
23152327
check(
23162328
assert_type(
23172329
df.rename_axis(
2318-
index=lambda name: name.upper(),
2319-
columns=lambda name: name.upper(),
2330+
index=lambda name: name.upper(), # pyright: ignore[reportUnknownArgumentType]
2331+
columns=lambda name: name.upper(), # pyright: ignore[reportUnknownArgumentType]
23202332
),
23212333
pd.DataFrame,
23222334
),
@@ -3119,7 +3131,12 @@ def test_to_dict_into_ordered_dict() -> None:
31193131
data = pd.DataFrame({("str", "rts"): [[1, 2, 4], [2, 3], [3]]})
31203132

31213133
check(
3122-
assert_type(data.to_dict(into=OrderedDict), OrderedDict[Any, Any]),
3134+
assert_type(
3135+
data.to_dict(
3136+
into=OrderedDict
3137+
), # pyright: ignore[reportUnknownArgumentType]
3138+
OrderedDict[Any, Any],
3139+
),
31233140
OrderedDict,
31243141
tuple,
31253142
)
@@ -3139,7 +3156,10 @@ def test_to_dict_into_ordered_dict() -> None:
31393156
)
31403157
check(
31413158
assert_type(
3142-
data.to_dict("records", into=OrderedDict), list[OrderedDict[Any, Any]]
3159+
data.to_dict(
3160+
"records", into=OrderedDict
3161+
), # pyright: ignore[reportUnknownArgumentType]
3162+
list[OrderedDict[Any, Any]],
31433163
),
31443164
list,
31453165
OrderedDict,
@@ -3762,7 +3782,13 @@ def test_combine() -> None:
37623782
take_smaller = lambda s1, s2: s1 if s1.sum() < s2.sum() else s2
37633783
assert_type(
37643784
check(
3765-
df1.combine(df2, take_smaller, fill_value=0, overwrite=False), pd.DataFrame
3785+
df1.combine(
3786+
df2,
3787+
take_smaller, # pyright: ignore[reportUnknownArgumentType]
3788+
fill_value=0,
3789+
overwrite=False,
3790+
),
3791+
pd.DataFrame,
37663792
),
37673793
pd.DataFrame,
37683794
)

tests/frame/test_groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_types_groupby() -> None:
123123
# GH 284
124124
df.groupby(df["col1"] > 2)
125125
df.groupby([df["col1"] > 2, df["col2"] % 2 == 1])
126-
df.groupby(lambda x: x)
126+
df.groupby(lambda x: x) # pyright: ignore[reportUnknownArgumentType]
127127
df.groupby([lambda x: x % 2, lambda x: x % 3])
128128
df.groupby(np.array([1, 0, 1]))
129129
df.groupby([np.array([1, 0, 0]), np.array([0, 0, 1])])

tests/indexes/test_indexes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,13 @@ def test_index_view() -> None:
17191719
# - pyright: ndarray[tuple[Any, ...], dtype[Any]]
17201720
check(assert_type(ind.view(np.ndarray), np.ndarray), np.ndarray) # type: ignore[assert-type]
17211721
else:
1722-
check(assert_type(ind.view(np.ndarray), np.ndarray[Any, Any]), np.ndarray)
1722+
check(
1723+
assert_type(
1724+
ind.view(np.ndarray), # pyright: ignore[reportUnknownArgumentType]
1725+
np.ndarray[Any, Any],
1726+
),
1727+
np.ndarray,
1728+
)
17231729

17241730
if sys.version_info >= (3, 11):
17251731

tests/scalars/test_scalars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
)
4242

4343
if not PD_LTE_23:
44-
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip
44+
from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration]
4545
else:
4646
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]
4747

tests/series/test_series.py

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
)
103103

104104
if not PD_LTE_23:
105-
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip
105+
from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration]
106106
else:
107107
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]
108108

@@ -387,7 +387,7 @@ def test_types_sort_values() -> None:
387387
s = pd.Series([4, 2, 1, 3])
388388
check(assert_type(s.sort_values(), "pd.Series[int]"), pd.Series, np.integer)
389389
if TYPE_CHECKING_INVALID_USAGE:
390-
check(assert_type(s.sort_values(0), pd.Series), pd.Series) # type: ignore[assert-type,call-overload] # pyright: ignore[reportAssertTypeFailure,reportCallIssue]
390+
check(assert_type(s.sort_values(0), pd.Series), pd.Series) # type: ignore[assert-type,call-overload] # pyright: ignore[reportAssertTypeFailure,reportCallIssue,reportUnknownArgumentType]
391391
check(assert_type(s.sort_values(axis=0), "pd.Series[int]"), pd.Series, np.integer)
392392
check(
393393
assert_type(s.sort_values(ascending=False), "pd.Series[int]"),
@@ -859,7 +859,14 @@ def get_depth(url: str) -> int:
859859
ss = s.astype(str)
860860
check(assert_type(ss.apply(get_depth), pd.Series), pd.Series, np.integer)
861861

862-
check(assert_type(s.apply(lambda x: pd.NA), pd.Series), pd.Series, NAType)
862+
check(
863+
assert_type(
864+
s.apply(lambda x: pd.NA), # pyright: ignore[reportUnknownArgumentType]
865+
pd.Series,
866+
),
867+
pd.Series,
868+
NAType,
869+
)
863870

864871

865872
def test_types_element_wise_arithmetic() -> None:
@@ -923,7 +930,7 @@ def test_types_groupby() -> None:
923930
s.groupby(s > 2)
924931
# GH 284
925932
s.groupby([s > 2, s % 2 == 1])
926-
s.groupby(lambda x: x)
933+
s.groupby(lambda x: x) # pyright: ignore[reportUnknownArgumentType]
927934
s.groupby([lambda x: x, lambda x: x.replace("a", "b")])
928935
s.groupby(np.array([1, 0, 1, 0]))
929936
s.groupby([np.array([1, 0, 0, 0]), np.array([0, 0, 1, 0])])
@@ -1144,33 +1151,39 @@ def transform_func(
11441151

11451152
check(
11461153
assert_type(
1147-
s.groupby(lambda x: x).transform(transform_func, True, kw_arg="foo"),
1154+
s.groupby(
1155+
lambda x: x # pyright: ignore[reportUnknownArgumentType]
1156+
).transform(transform_func, True, kw_arg="foo"),
11481157
"pd.Series[float]",
11491158
),
11501159
pd.Series,
11511160
float,
11521161
)
11531162
check(
11541163
assert_type(
1155-
s.groupby(lambda x: x).transform(
1156-
transform_func, True, engine="cython", kw_arg="foo"
1157-
),
1164+
s.groupby(
1165+
lambda x: x # pyright: ignore[reportUnknownArgumentType]
1166+
).transform(transform_func, True, engine="cython", kw_arg="foo"),
11581167
"pd.Series[float]",
11591168
),
11601169
pd.Series,
11611170
float,
11621171
)
11631172
check(
11641173
assert_type(
1165-
s.groupby(lambda x: x).transform("mean"),
1166-
"pd.Series",
1174+
s.groupby(
1175+
lambda x: x # pyright: ignore[reportUnknownArgumentType]
1176+
).transform("mean"),
1177+
pd.Series,
11671178
),
11681179
pd.Series,
11691180
)
11701181
check(
11711182
assert_type(
1172-
s.groupby(lambda x: x).transform("first"),
1173-
"pd.Series",
1183+
s.groupby(
1184+
lambda x: x # pyright: ignore[reportUnknownArgumentType]
1185+
).transform("first"),
1186+
pd.Series,
11741187
),
11751188
pd.Series,
11761189
)
@@ -1429,7 +1442,12 @@ def test_types_rename_axis() -> None:
14291442
check(assert_type(s.rename_axis(index=["A"]), "pd.Series[int]"), pd.Series)
14301443
check(assert_type(s.rename_axis(index={"a": "A"}), "pd.Series[int]"), pd.Series)
14311444
check(
1432-
assert_type(s.rename_axis(index=lambda name: name.upper()), "pd.Series[int]"),
1445+
assert_type(
1446+
s.rename_axis(
1447+
index=lambda name: name.upper() # pyright: ignore[reportUnknownArgumentType]
1448+
),
1449+
"pd.Series[int]",
1450+
),
14331451
pd.Series,
14341452
)
14351453
check(assert_type(s.rename_axis(index=None), "pd.Series[int]"), pd.Series)
@@ -3001,7 +3019,15 @@ def test_types_apply_set() -> None:
30013019
series_of_lists: pd.Series = pd.Series(
30023020
{"list1": [1, 2, 3], "list2": ["a", "b", "c"], "list3": [True, False, True]}
30033021
)
3004-
check(assert_type(series_of_lists.apply(lambda x: set(x)), pd.Series), pd.Series)
3022+
check(
3023+
assert_type(
3024+
series_of_lists.apply(
3025+
lambda x: set(x) # pyright: ignore[reportUnknownArgumentType]
3026+
),
3027+
pd.Series,
3028+
),
3029+
pd.Series,
3030+
)
30053031

30063032

30073033
def test_prefix_summix_axis() -> None:
@@ -3047,7 +3073,13 @@ def test_convert_dtypes_dtype_backend() -> None:
30473073
def test_apply_returns_none() -> None:
30483074
# GH 557
30493075
s = pd.Series([1, 2, 3])
3050-
check(assert_type(s.apply(lambda x: None), pd.Series), pd.Series)
3076+
check(
3077+
assert_type(
3078+
s.apply(lambda x: None), # pyright: ignore[reportUnknownArgumentType]
3079+
pd.Series,
3080+
),
3081+
pd.Series,
3082+
)
30513083

30523084

30533085
def test_to_json_mode() -> None:
@@ -3579,7 +3611,12 @@ def test_apply_dateoffset() -> None:
35793611
s = pd.Series(months)
35803612
check(
35813613
assert_type(
3582-
s.apply(lambda x: pd.DateOffset(months=x)), "pd.Series[BaseOffset]"
3614+
s.apply(
3615+
lambda x: pd.DateOffset(
3616+
months=x # pyright: ignore[reportUnknownArgumentType]
3617+
)
3618+
),
3619+
"pd.Series[BaseOffset]",
35833620
),
35843621
pd.Series,
35853622
pd.DateOffset,

0 commit comments

Comments
 (0)