Skip to content

Commit 0fcf62d

Browse files
committed
enable reportUnknownArgumentType
1 parent 0923f15 commit 0fcf62d

File tree

17 files changed

+68
-74
lines changed

17 files changed

+68
-74
lines changed

pandas-stubs/core/dtypes/missing.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ from pandas._libs.tslibs import NaTType
1717
from pandas._typing import (
1818
Scalar,
1919
ScalarT,
20+
ScalarT0,
2021
ShapeT,
2122
np_1darray_bool,
2223
np_ndarray,
@@ -54,6 +55,6 @@ def notna(obj: np_ndarray[ShapeT]) -> np_ndarray[ShapeT, np.bool]: ...
5455
@overload
5556
def notna(obj: list[Any]) -> np_ndarray_bool: ...
5657
@overload
57-
def notna(obj: ScalarT | NaTType | NAType | None) -> TypeIs[ScalarT]: ...
58+
def notna(obj: ScalarT0 | NaTType | NAType | None) -> TypeIs[ScalarT0]: ...
5859

5960
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pyright: reportUnknownArgumentType=false
12
from __future__ import annotations
23

34
from collections import (
@@ -76,7 +77,7 @@
7677
_PandasNamedTuple: TypeAlias = tuple
7778

7879
if not PD_LTE_23:
79-
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip
80+
from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration]
8081
else:
8182
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]
8283

@@ -2315,8 +2316,7 @@ def test_types_rename_axis() -> None:
23152316
check(
23162317
assert_type(
23172318
df.rename_axis(
2318-
index=lambda name: name.upper(),
2319-
columns=lambda name: name.upper(),
2319+
index=lambda name: name.upper(), columns=lambda name: name.upper()
23202320
),
23212321
pd.DataFrame,
23222322
),

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: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pyright: reportUnknownArgumentType=false
12
from __future__ import annotations
23

34
from collections.abc import (
@@ -102,7 +103,7 @@
102103
)
103104

104105
if not PD_LTE_23:
105-
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip
106+
from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration]
106107
else:
107108
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]
108109

@@ -1160,20 +1161,8 @@ def transform_func(
11601161
pd.Series,
11611162
float,
11621163
)
1163-
check(
1164-
assert_type(
1165-
s.groupby(lambda x: x).transform("mean"),
1166-
"pd.Series",
1167-
),
1168-
pd.Series,
1169-
)
1170-
check(
1171-
assert_type(
1172-
s.groupby(lambda x: x).transform("first"),
1173-
"pd.Series",
1174-
),
1175-
pd.Series,
1176-
)
1164+
check(assert_type(s.groupby(lambda x: x).transform("mean"), pd.Series), pd.Series)
1165+
check(assert_type(s.groupby(lambda x: x).transform("first"), pd.Series), pd.Series)
11771166

11781167

11791168
def test_types_groupby_aggregate() -> None:
@@ -3254,11 +3243,7 @@ def first_arg_series(
32543243
check(
32553244
assert_type(
32563245
ser.pipe(
3257-
first_arg_series,
3258-
1,
3259-
[1.0, 2.0],
3260-
argument_2="hi",
3261-
keyword_only=(1, 2),
3246+
first_arg_series, 1, [1.0, 2.0], argument_2="hi", keyword_only=(1, 2)
32623247
),
32633248
pd.Series,
32643249
),
@@ -3319,16 +3304,7 @@ def first_arg_series(
33193304
def first_arg_not_series(argument_1: int, ser: pd.Series) -> pd.Series:
33203305
return ser
33213306

3322-
check(
3323-
assert_type(
3324-
ser.pipe(
3325-
(first_arg_not_series, "ser"),
3326-
1,
3327-
),
3328-
pd.Series,
3329-
),
3330-
pd.Series,
3331-
)
3307+
check(assert_type(ser.pipe((first_arg_not_series, "ser"), 1), pd.Series), pd.Series)
33323308

33333309
if TYPE_CHECKING_INVALID_USAGE:
33343310
ser.pipe(

0 commit comments

Comments
 (0)