Skip to content

Commit 51fbbbc

Browse files
committed
pyrefly implicit-any-lambda
1 parent 7619728 commit 51fbbbc

8 files changed

Lines changed: 10 additions & 52 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ min-severity = "warn"
344344

345345
[tool.pyrefly.errors]
346346
explicit-any = false # We do use implicit Any
347+
implicit-any-lambda = false # Users do this
347348
implicit-any-type-argument = false # We do use implicit Any
348349
implicit-bool = false # We do use implicit bool
349350
untyped-import = false # Import discovery

tests/frame/test_frame.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ def test_types_assign() -> None:
262262
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
263263

264264
check(
265-
# pyrefly: ignore[implicit-any-lambda]
266265
assert_type(df.assign(col3=lambda frame: frame.sum(axis=1)), pd.DataFrame),
267266
pd.DataFrame,
268267
)
@@ -272,11 +271,8 @@ def test_types_assign() -> None:
272271
check(
273272
assert_type(
274273
df.assign(
275-
# pyrefly: ignore[implicit-any-lambda]
276274
b=lambda df: range(len(df)),
277-
# pyrefly: ignore[implicit-any-lambda]
278275
c=lambda _: [10, 20, 30],
279-
# pyrefly: ignore[implicit-any-lambda]
280276
d=lambda _: (10, 20, 30),
281277
),
282278
pd.DataFrame,
@@ -301,10 +297,7 @@ def test_assign() -> None:
301297
df = pd.DataFrame({"a": [1, 2, 3], 1: [4, 5, 6]})
302298

303299
my_unnamed_func = ( # pyright: ignore[reportUnknownVariableType]
304-
lambda df: df[ # pyright: ignore[reportUnknownLambdaType] # pyrefly: ignore[implicit-any-lambda]
305-
"a"
306-
]
307-
* 2
300+
lambda df: df["a"] * 2 # pyright: ignore[reportUnknownLambdaType]
308301
)
309302

310303
def my_named_func_1(df: pd.DataFrame) -> pd.Series[str]:
@@ -313,20 +306,16 @@ def my_named_func_1(df: pd.DataFrame) -> pd.Series[str]:
313306
def my_named_func_2(df: pd.DataFrame) -> pd.Series:
314307
return df["a"]
315308

316-
# pyrefly: ignore[implicit-any-lambda]
317309
check(assert_type(df.assign(c=lambda df: df["a"] * 2), pd.DataFrame), pd.DataFrame)
318310
check(
319-
# pyrefly: ignore[implicit-any-lambda]
320311
assert_type(df.assign(c=lambda df: df["a"].index), pd.DataFrame),
321312
pd.DataFrame,
322313
)
323314
check(
324-
# pyrefly: ignore[implicit-any-lambda]
325315
assert_type(df.assign(c=lambda df: df["a"].to_numpy()), pd.DataFrame),
326316
pd.DataFrame,
327317
)
328318
check(
329-
# pyrefly: ignore[implicit-any-lambda]
330319
assert_type(df.assign(c=lambda df: df["a"].max()), pd.DataFrame),
331320
pd.DataFrame,
332321
)
@@ -345,7 +334,6 @@ def my_named_func_2(df: pd.DataFrame) -> pd.Series:
345334
check(assert_type(df.assign(c=my_named_func_2), pd.DataFrame), pd.DataFrame)
346335
check(assert_type(df.assign(c=None), pd.DataFrame), pd.DataFrame)
347336
check(
348-
# pyrefly: ignore[implicit-any-lambda]
349337
assert_type(df.assign(foo=lambda df: df.get("abc", None)), pd.DataFrame),
350338
pd.DataFrame,
351339
)
@@ -508,7 +496,6 @@ def test_types_sort_index() -> None:
508496
def test_types_sort_index_with_key() -> None:
509497
df = pd.DataFrame(data={"col1": [1, 2, 3, 4]}, index=["a", "b", "C", "d"])
510498
check(
511-
# pyrefly: ignore[implicit-any-lambda]
512499
assert_type(df.sort_index(key=lambda k: k.str.lower()), pd.DataFrame),
513500
pd.DataFrame,
514501
)
@@ -598,7 +585,6 @@ def test_types_sort_values_with_key() -> None:
598585
# This was added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
599586
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
600587
check(
601-
# pyrefly: ignore[implicit-any-lambda]
602588
assert_type(df.sort_values(by="col1", key=lambda k: -k), pd.DataFrame),
603589
pd.DataFrame,
604590
)
@@ -1356,7 +1342,6 @@ def test_types_map() -> None:
13561342
check(
13571343
assert_type(
13581344
df.map(
1359-
# pyrefly: ignore[implicit-any-lambda]
13601345
lambda x: x # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
13611346
** 2
13621347
),
@@ -2697,7 +2682,6 @@ def test_types_rename() -> None:
26972682
check(assert_type(df.rename(columns={None: "b"}), pd.DataFrame), pd.DataFrame)
26982683
check(assert_type(df.rename(columns={"": "b"}), pd.DataFrame), pd.DataFrame)
26992684
check(
2700-
# pyrefly: ignore[implicit-any-lambda]
27012685
assert_type(df.rename(columns=lambda s: s.upper()), pd.DataFrame),
27022686
pd.DataFrame,
27032687
)
@@ -2756,9 +2740,7 @@ def test_types_rename_axis() -> None:
27562740
check(
27572741
assert_type(
27582742
df.rename_axis(
2759-
# pyrefly: ignore[implicit-any-lambda]
27602743
index=lambda name: name.upper(), # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType,reportUnknownMemberType]
2761-
# pyrefly: ignore[implicit-any-lambda]
27622744
columns=lambda name: name.upper(), # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType,reportUnknownMemberType]
27632745
),
27642746
pd.DataFrame,
@@ -4168,7 +4150,7 @@ def test_transpose() -> None:
41684150
def test_combine() -> None:
41694151
df1 = pd.DataFrame({"A": [0, 0], "B": [4, 4]})
41704152
df2 = pd.DataFrame({"A": [1, 1], "B": [3, 3]})
4171-
# pyrefly: ignore[implicit-any-lambda]
4153+
41724154
take_smaller = lambda s1, s2: ( # pyright: ignore[reportUnknownLambdaType,reportUnknownVariableType]
41734155
s1 if s1.sum() < s2.sum() else s2 # pyright: ignore[reportUnknownMemberType]
41744156
)
@@ -4560,14 +4542,12 @@ def func_e(x: pd.DataFrame, k: int) -> pd.Series:
45604542
return x.max() - k * x.min()
45614543

45624544
check(
4563-
# pyrefly: ignore[implicity-any-lambda]
45644545
assert_type(df.rolling(2).pipe(lambda x: x.min() - x.max()), pd.DataFrame),
45654546
pd.DataFrame,
45664547
)
45674548
check(assert_type(df.rolling(2).pipe(func_r, k=2), pd.DataFrame), pd.DataFrame)
45684549

45694550
check(
4570-
# pyrefly: ignore[implicity-any-lambda]
45714551
assert_type(df.expanding().pipe(lambda x: x.min() - x.max()), pd.DataFrame),
45724552
pd.DataFrame,
45734553
)

tests/frame/test_groupby.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,13 @@ def test_types_groupby() -> None:
162162
)
163163
check(
164164
assert_type(
165-
# pyrefly: ignore[implicit-any-lambda]
166165
df.groupby(lambda x: x), # pyright: ignore[reportUnknownArgumentType]
167166
"DataFrameGroupBy[tuple[Hashable, ...], Literal[True]]",
168167
),
169168
DataFrameGroupBy,
170169
)
171170
check(
172171
assert_type(
173-
# pyrefly: ignore[implicit-any-lambda]
174172
df.groupby([lambda x: x % 2, lambda x: x % 3]),
175173
"DataFrameGroupBy[tuple[Hashable, ...], Literal[True]]",
176174
),
@@ -239,7 +237,6 @@ def test_types_groupby() -> None:
239237
check(
240238
assert_type(
241239
df.groupby(by="col1", sort=False, as_index=True).transform(
242-
# pyrefly: ignore[implicit-any-lambda]
243240
lambda x: x.max()
244241
),
245242
pd.DataFrame,
@@ -700,10 +697,10 @@ def test_groupby_and_transform() -> None:
700697
grouped = df.groupby("A")[["C", "D"]]
701698
grouped1 = ser.groupby(ser > 100)
702699
c1 = grouped.transform("sum")
703-
# pyrefly: ignore[implicit-any-lambda]
700+
704701
c2 = grouped.transform(lambda x: (x - x.mean()) / x.std())
705702
c3 = grouped1.transform("cumsum")
706-
# pyrefly: ignore[implicit-any-lambda]
703+
707704
c4 = grouped1.transform(lambda x: x.max() - x.min())
708705
check(assert_type(c1, pd.DataFrame), pd.DataFrame)
709706
check(assert_type(c2, pd.DataFrame), pd.DataFrame)

tests/frame/test_indexing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def test_indexslice_getitem() -> None:
154154
# GH 300
155155
df = (
156156
pd.DataFrame({"x": [1, 2, 2, 3, 4], "y": [10, 20, 30, 40, 10]})
157-
# pyrefly: ignore[implicit-any-lambda]
158-
.assign(z=lambda df: df.x * df.y).set_index(["x", "y"])
157+
.assign(z=lambda df: df.x * df.y)
158+
.set_index(["x", "y"])
159159
)
160160
ind = pd.Index([2, 3])
161161
check(
@@ -539,7 +539,6 @@ def select3(_: pd.DataFrame) -> int:
539539
assert_type(
540540
df.loc[
541541
:,
542-
# pyrefly: ignore[implicit-any-lambda]
543542
lambda df: df.columns.str.startswith( # pyright: ignore[reportUnknownLambdaType,reportUnknownMemberType]
544543
"x"
545544
),

tests/series/test_indexing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,15 @@ def test_iloc_setitem_ndarray() -> None:
194194
def test_loc_callable() -> None:
195195
# GH 586
196196
s = pd.Series([1, 2])
197-
# pyrefly: ignore[implicit-any-lambda]
198197
check(assert_type(s.loc[lambda x: x > 1], "pd.Series[int]"), pd.Series, np.integer)
199198

200199

201200
def test_series_setitem_multiindex() -> None:
202201
# GH 767
203202
df = (
204203
pd.DataFrame({"x": [1, 2, 3, 4]})
205-
# pyrefly: ignore[implicit-any-lambda]
206-
.assign(y=lambda df: df["x"] * 10, z=lambda df: df["x"] * 100).set_index(
207-
["x", "y"]
208-
)
204+
.assign(y=lambda df: df["x"] * 10, z=lambda df: df["x"] * 100)
205+
.set_index(["x", "y"])
209206
)
210207
ind = pd.Index([2, 3])
211208
s = df["z"]

tests/series/test_series.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ def test_types_sort_index() -> None:
378378
def test_types_sort_index_with_key() -> None:
379379
s = pd.Series([1, 2, 3], index=["a", "B", "c"])
380380
check(
381-
# pyrefly: ignore[implicit-any-lambda]
382381
assert_type(s.sort_index(key=lambda k: k.str.lower()), "pd.Series[int]"),
383382
pd.Series,
384383
np.integer,
@@ -413,7 +412,6 @@ def test_types_sort_values() -> None:
413412
def test_types_sort_values_with_key() -> None:
414413
s = pd.Series([1, 2, 3], index=[2, 3, 1])
415414
check(
416-
# pyrefly: ignore[implicit-any-lambda]
417415
assert_type(s.sort_values(key=lambda k: -k), "pd.Series[int]"),
418416
pd.Series,
419417
np.integer,
@@ -846,7 +844,7 @@ def get_depth(url: str) -> int:
846844
check(
847845
assert_type(
848846
s.apply(
849-
lambda x: pd.NA # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType] # pyrefly: ignore[implicit-any-lambda]
847+
lambda x: pd.NA # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
850848
),
851849
pd.Series,
852850
),
@@ -937,14 +935,11 @@ def test_types_groupby() -> None:
937935
# GH 284
938936
s.groupby([s > 2, s % 2 == 1])
939937
s.groupby(
940-
# pyrefly: ignore[implicit-any-lambda]
941938
lambda x: x # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
942939
)
943940
s.groupby(
944941
[
945-
# pyrefly: ignore[implicit-any-lambda]
946942
lambda x: x, # pyright: ignore[reportUnknownLambdaType]
947-
# pyrefly: ignore[implicit-any-lambda]
948943
lambda x: x.replace( # pyright: ignore[reportUnknownLambdaType,reportUnknownMemberType]
949944
"a", "b"
950945
),
@@ -1164,7 +1159,6 @@ def transform_func(
11641159
check(
11651160
assert_type(
11661161
s.groupby(
1167-
# pyrefly: ignore[implicit-any-lambda]
11681162
lambda x: x # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
11691163
).transform(transform_func, True, kw_arg="foo"),
11701164
"pd.Series[float]",
@@ -1175,7 +1169,6 @@ def transform_func(
11751169
check(
11761170
assert_type(
11771171
s.groupby(
1178-
# pyrefly: ignore[implicit-any-lambda]
11791172
lambda x: x # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
11801173
).transform(transform_func, True, engine="cython", kw_arg="foo"),
11811174
"pd.Series[float]",
@@ -1186,7 +1179,6 @@ def transform_func(
11861179
check(
11871180
assert_type(
11881181
s.groupby(
1189-
# pyrefly: ignore[implicit-any-lambda]
11901182
lambda x: x # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
11911183
).transform("mean"),
11921184
pd.Series,
@@ -1196,7 +1188,6 @@ def transform_func(
11961188
check(
11971189
assert_type(
11981190
s.groupby(
1199-
# pyrefly: ignore[implicit-any-lambda]
12001191
lambda x: x # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
12011192
).transform("first"),
12021193
pd.Series,
@@ -1448,7 +1439,6 @@ def test_types_rename_axis() -> None:
14481439
check(
14491440
assert_type(
14501441
s.rename_axis(
1451-
# pyrefly: ignore[implicit-any-lambda]
14521442
index=lambda name: name.upper() # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType,reportUnknownMemberType]
14531443
),
14541444
"pd.Series[int]",
@@ -1539,7 +1529,6 @@ def add1(x: int) -> int:
15391529
np.integer,
15401530
)
15411531
check(
1542-
# pyrefly: ignore[implicit-any-lambda]
15431532
assert_type(pd.Series([1, 2, 3]).rename(lambda x: x**2, inplace=True), None),
15441533
type(None),
15451534
)
@@ -2952,7 +2941,6 @@ def test_types_apply_set() -> None:
29522941
check(
29532942
assert_type(
29542943
series_of_lists.apply(
2955-
# pyrefly: ignore[implicit-any-lambda]
29562944
lambda x: set( # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
29572945
x # pyright: ignore[reportUnknownArgumentType]
29582946
)
@@ -3009,7 +2997,6 @@ def test_apply_returns_none() -> None:
30092997
check(
30102998
assert_type(
30112999
s.apply(
3012-
# pyrefly: ignore[implicit-any-lambda]
30133000
lambda x: None # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
30143001
),
30153002
pd.Series,
@@ -3588,7 +3575,6 @@ def test_apply_dateoffset() -> None:
35883575
check(
35893576
assert_type(
35903577
s.apply(
3591-
# pyrefly: ignore[implicit-any-lambda]
35923578
lambda x: pd.DateOffset( # pyright: ignore[reportUnknownArgumentType,reportUnknownLambdaType]
35933579
months=x # pyright: ignore[reportUnknownArgumentType]
35943580
)

tests/test_io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,6 @@ def test_types_read_csv_num(tmp_path: Path) -> None:
737737
assert_type(
738738
pd.read_csv(
739739
path_str,
740-
# pyrefly: ignore[implicit-any-lambda]
741740
skiprows=lambda x: x in [0, 2],
742741
skip_blank_lines=True,
743742
dayfirst=False,

tests/test_pandas.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ def test_types_concat() -> None:
253253

254254
check(
255255
assert_type(
256-
# pyrefly: ignore[implicit-any-lambda]
257256
pd.concat(map(lambda _: s2, ["some_value", 3]), axis=1), # noqa: C417
258257
pd.DataFrame,
259258
),

0 commit comments

Comments
 (0)