@@ -1398,21 +1398,124 @@ 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
+ df .pipe (qux , 1 , [1.0 , 2.0 ], argument_2 = "hi" , keyword_only = (1 , 2 )),
1430
+ pd .DataFrame ,
1431
+ ),
1432
+ pd .DataFrame ,
1433
+ )
1434
+
1435
+ if TYPE_CHECKING_INVALID_USAGE :
1436
+ df .pipe (
1437
+ qux , # type: ignore[arg-type]
1438
+ "a" , # pyright: ignore[reportGeneralTypeIssues]
1439
+ [1.0 , 2.0 ],
1440
+ argument_2 = "hi" ,
1441
+ keyword_only = (1 , 2 ),
1442
+ )
1443
+ df .pipe (
1444
+ qux , # type: ignore[arg-type]
1445
+ 1 ,
1446
+ [1.0 , "b" ], # pyright: ignore[reportGeneralTypeIssues]
1447
+ argument_2 = "hi" ,
1448
+ keyword_only = (1 , 2 ),
1449
+ )
1450
+ df .pipe (
1451
+ qux , # type: ignore[arg-type]
1452
+ 1 ,
1453
+ [1.0 , 2.0 ],
1454
+ argument_2 = 11 , # pyright: ignore[reportGeneralTypeIssues]
1455
+ keyword_only = (1 , 2 ),
1456
+ )
1457
+ df .pipe (
1458
+ qux , # type: ignore[arg-type]
1459
+ 1 ,
1460
+ [1.0 , 2.0 ],
1461
+ argument_2 = "hi" ,
1462
+ keyword_only = (1 ,), # pyright: ignore[reportGeneralTypeIssues]
1463
+ )
1464
+ df .pipe (
1465
+ qux , # type: ignore[arg-type]
1466
+ 1 ,
1467
+ [1.0 , 2.0 ],
1468
+ argument_3 = "hi" , # pyright: ignore[reportGeneralTypeIssues]
1469
+ keyword_only = (1 , 2 ),
1470
+ )
1471
+ df .pipe (
1472
+ qux , # type: ignore[arg-type]
1473
+ 1 ,
1474
+ [1.0 , 2.0 ],
1475
+ 11 ,
1476
+ (1 , 2 ), # pyright: ignore[reportGeneralTypeIssues]
1477
+ )
1478
+ df .pipe (
1479
+ qux , # type: ignore[arg-type]
1480
+ positional_only = 1 , # pyright: ignore[reportGeneralTypeIssues]
1481
+ argument_1 = [1.0 , 2.0 ],
1482
+ argument_2 = 11 ,
1483
+ keyword_only = (1 , 2 ),
1484
+ )
1485
+
1486
+ def dataframe_not_first_arg (x : int , df : pd .DataFrame ) -> pd .DataFrame :
1487
+ return df
1488
+
1489
+ # pyright does not like that the paramspec is not specified
1490
+ check (
1491
+ assert_type (
1492
+ df .pipe (
1493
+ (
1494
+ dataframe_not_first_arg ,
1495
+ "df" ,
1496
+ ),
1497
+ 1 , # pyright: ignore[reportGeneralTypeIssues]
1498
+ ),
1499
+ pd .DataFrame ,
1500
+ ),
1501
+ pd .DataFrame ,
1502
+ )
1503
+
1504
+ if TYPE_CHECKING_INVALID_USAGE :
1505
+ df .pipe (
1506
+ (
1507
+ dataframe_not_first_arg , # type: ignore[arg-type]
1508
+ 1 , # pyright: ignore[reportGeneralTypeIssues]
1509
+ ),
1510
+ 1 , # pyright: ignore[reportGeneralTypeIssues]
1511
+ )
1512
+ df .pipe (
1513
+ (
1514
+ 1 , # type: ignore[arg-type]
1515
+ "df" ,
1516
+ ), # pyright: ignore[reportGeneralTypeIssues]
1517
+ 1 , # pyright: ignore[reportGeneralTypeIssues]
1518
+ )
1416
1519
1417
1520
1418
1521
# set_flags() method added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
0 commit comments