@@ -1398,21 +1398,125 @@ def foo(df: pd.DataFrame) -> pd.DataFrame:
1398
1398
.pipe (foo )
1399
1399
)
1400
1400
1401
+ df = pd .DataFrame ({"a" : [1 ], "b" : [2 ]})
1401
1402
check (assert_type (val , pd .DataFrame ), pd .DataFrame )
1402
1403
1403
- check (assert_type (pd . DataFrame ({ "a" : [ 1 ]}) .pipe (foo ), pd .DataFrame ), pd .DataFrame )
1404
+ check (assert_type (df .pipe (foo ), pd .DataFrame ), pd .DataFrame )
1404
1405
1405
1406
def bar (val : Styler ) -> Styler :
1406
1407
return val
1407
1408
1408
- check (
1409
- assert_type (pd .DataFrame ({"a" : [1 ], "b" : [1 ]}).style .pipe (bar ), Styler ), Styler
1410
- )
1409
+ check (assert_type (df .style .pipe (bar ), Styler ), Styler )
1411
1410
1412
1411
def baz (val : Styler ) -> str :
1413
1412
return val .to_latex ()
1414
1413
1415
- check (assert_type (pd .DataFrame ({"a" : [1 ], "b" : [1 ]}).style .pipe (baz ), str ), str )
1414
+ check (assert_type (df .style .pipe (baz ), str ), str )
1415
+
1416
+ def qux (
1417
+ df : pd .DataFrame ,
1418
+ positional_only : int ,
1419
+ / ,
1420
+ argument_1 : list [float ],
1421
+ argument_2 : str ,
1422
+ * ,
1423
+ keyword_only : tuple [int , int ],
1424
+ ) -> pd .DataFrame :
1425
+ return pd .DataFrame (df )
1426
+
1427
+ check (
1428
+ assert_type (
1429
+ # FIXME: Remove ignore when pyright releases fix:
1430
+ # https://github.com/microsoft/pyright/pull/6797
1431
+ df .pipe (qux , 1 , [1.0 , 2.0 ], argument_2 = "hi" , keyword_only = (1 , 2 )), # pyright: ignore[reportGeneralTypeIssues]
1432
+ pd .DataFrame ,
1433
+ ),
1434
+ pd .DataFrame ,
1435
+ )
1436
+
1437
+ if TYPE_CHECKING_INVALID_USAGE :
1438
+ df .pipe (
1439
+ qux ,
1440
+ "a" , # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
1441
+ [1.0 , 2.0 ],
1442
+ argument_2 = "hi" ,
1443
+ keyword_only = (1 , 2 ),
1444
+ )
1445
+ df .pipe (
1446
+ qux ,
1447
+ 1 ,
1448
+ [1.0 , "b" ], # type: ignore[list-item] # pyright: ignore[reportGeneralTypeIssues]
1449
+ argument_2 = "hi" ,
1450
+ keyword_only = (1 , 2 ),
1451
+ )
1452
+ df .pipe (
1453
+ qux ,
1454
+ 1 ,
1455
+ [1.0 , 2.0 ],
1456
+ argument_2 = 11 , # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
1457
+ keyword_only = (1 , 2 ),
1458
+ )
1459
+ df .pipe (
1460
+ qux ,
1461
+ 1 ,
1462
+ [1.0 , 2.0 ],
1463
+ argument_2 = "hi" ,
1464
+ keyword_only = (1 ,), # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
1465
+ )
1466
+ df .pipe ( # type: ignore[call-arg]
1467
+ qux ,
1468
+ 1 ,
1469
+ [1.0 , 2.0 ],
1470
+ argument_3 = "hi" , # pyright: ignore[reportGeneralTypeIssues]
1471
+ keyword_only = (1 , 2 ),
1472
+ )
1473
+ df .pipe ( # type: ignore[misc]
1474
+ qux ,
1475
+ 1 ,
1476
+ [1.0 , 2.0 ],
1477
+ 11 , # type: ignore[arg-type]
1478
+ (1 , 2 ), # pyright: ignore[reportGeneralTypeIssues]
1479
+ )
1480
+ df .pipe ( # type: ignore[call-arg]
1481
+ qux ,
1482
+ positional_only = 1 , # pyright: ignore[reportGeneralTypeIssues]
1483
+ argument_1 = [1.0 , 2.0 ],
1484
+ argument_2 = 11 , # type: ignore[arg-type]
1485
+ keyword_only = (1 , 2 ),
1486
+ )
1487
+
1488
+ def dataframe_not_first_arg (x : int , df : pd .DataFrame ) -> pd .DataFrame :
1489
+ return df
1490
+
1491
+ check (
1492
+ assert_type (
1493
+ df .pipe (
1494
+ (
1495
+ dataframe_not_first_arg ,
1496
+ "df" ,
1497
+ ),
1498
+ 1 ,
1499
+ ),
1500
+ pd .DataFrame ,
1501
+ ),
1502
+ pd .DataFrame ,
1503
+ )
1504
+
1505
+ if TYPE_CHECKING_INVALID_USAGE :
1506
+ df .pipe (
1507
+ (
1508
+ dataframe_not_first_arg , # type: ignore[arg-type]
1509
+ 1 , # pyright: ignore[reportGeneralTypeIssues]
1510
+ ),
1511
+ 1 ,
1512
+ )
1513
+ df .pipe (
1514
+ ( # pyright: ignore[reportGeneralTypeIssues]
1515
+ 1 , # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
1516
+ "df" ,
1517
+ ),
1518
+ 1 ,
1519
+ )
1416
1520
1417
1521
1418
1522
# set_flags() method added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
0 commit comments