@@ -56,7 +56,6 @@ from pandas.core.reshape.pivot import (
56
56
)
57
57
from pandas .core .series import (
58
58
Series ,
59
- UnknownSeries ,
60
59
)
61
60
from pandas .core .window import (
62
61
Expanding ,
@@ -79,7 +78,7 @@ from pandas._libs.tslibs import BaseOffset
79
78
from pandas ._libs .tslibs .nattype import NaTType
80
79
from pandas ._libs .tslibs .offsets import DateOffset
81
80
from pandas ._typing import (
82
- S1 ,
81
+ S2 ,
83
82
AggFuncTypeBase ,
84
83
AggFuncTypeDictFrame ,
85
84
AggFuncTypeDictSeries ,
@@ -1319,11 +1318,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1319
1318
@overload
1320
1319
def stack (
1321
1320
self , level : Level | list [Level ] = ..., dropna : _bool = ..., sort : _bool = ...
1322
- ) -> Self | Series [ Any ] : ...
1321
+ ) -> Self | Series : ...
1323
1322
@overload
1324
1323
def stack (
1325
1324
self , level : Level | list [Level ] = ..., future_stack : _bool = ...
1326
- ) -> Self | Series [ Any ] : ...
1325
+ ) -> Self | Series : ...
1327
1326
def explode (
1328
1327
self , column : Sequence [Hashable ], ignore_index : _bool = ...
1329
1328
) -> Self : ...
@@ -1383,7 +1382,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1383
1382
@overload
1384
1383
def apply (
1385
1384
self ,
1386
- f : Callable [..., ListLikeExceptSeriesAndStr | Series [ Any ] ],
1385
+ f : Callable [..., ListLikeExceptSeriesAndStr | Series ],
1387
1386
axis : AxisIndex = ...,
1388
1387
raw : _bool = ...,
1389
1388
result_type : None = ...,
@@ -1393,13 +1392,14 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1393
1392
@overload
1394
1393
def apply (
1395
1394
self ,
1396
- f : Callable [..., S1 | NAType ],
1395
+ # Use S2 (TypeVar without `default=Any`) instead of S1 due to https://github.com/python/mypy/issues/19182.
1396
+ f : Callable [..., S2 | NAType ],
1397
1397
axis : AxisIndex = ...,
1398
1398
raw : _bool = ...,
1399
1399
result_type : None = ...,
1400
1400
args : Any = ...,
1401
1401
** kwargs : Any ,
1402
- ) -> Series [S1 ]: ...
1402
+ ) -> Series [S2 ]: ...
1403
1403
# Since non-scalar type T is not supported in Series[T],
1404
1404
# we separate this overload from the above one
1405
1405
@overload
@@ -1411,24 +1411,25 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1411
1411
result_type : None = ...,
1412
1412
args : Any = ...,
1413
1413
** kwargs : Any ,
1414
- ) -> Series [ Any ] : ...
1414
+ ) -> Series : ...
1415
1415
1416
1416
# apply() overloads with keyword result_type, and axis does not matter
1417
1417
@overload
1418
1418
def apply (
1419
1419
self ,
1420
- f : Callable [..., S1 | NAType ],
1420
+ # Use S2 (TypeVar without `default=Any`) instead of S1 due to https://github.com/python/mypy/issues/19182.
1421
+ f : Callable [..., S2 | NAType ],
1421
1422
axis : Axis = ...,
1422
1423
raw : _bool = ...,
1423
1424
args : Any = ...,
1424
1425
* ,
1425
1426
result_type : Literal ["expand" , "reduce" ],
1426
1427
** kwargs : Any ,
1427
- ) -> Series [S1 ]: ...
1428
+ ) -> Series [S2 ]: ...
1428
1429
@overload
1429
1430
def apply (
1430
1431
self ,
1431
- f : Callable [..., ListLikeExceptSeriesAndStr | Series [ Any ] | Mapping [Any , Any ]],
1432
+ f : Callable [..., ListLikeExceptSeriesAndStr | Series | Mapping [Any , Any ]],
1432
1433
axis : Axis = ...,
1433
1434
raw : _bool = ...,
1434
1435
args : Any = ...,
@@ -1446,12 +1447,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1446
1447
* ,
1447
1448
result_type : Literal ["reduce" ],
1448
1449
** kwargs : Any ,
1449
- ) -> Series [ Any ] : ...
1450
+ ) -> Series : ...
1450
1451
@overload
1451
1452
def apply (
1452
1453
self ,
1453
1454
f : Callable [
1454
- ..., ListLikeExceptSeriesAndStr | Series [ Any ] | Scalar | Mapping [Any , Any ]
1455
+ ..., ListLikeExceptSeriesAndStr | Series | Scalar | Mapping [Any , Any ]
1455
1456
],
1456
1457
axis : Axis = ...,
1457
1458
raw : _bool = ...,
@@ -1465,27 +1466,28 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1465
1466
@overload
1466
1467
def apply (
1467
1468
self ,
1468
- f : Callable [..., Series [ Any ] ],
1469
+ f : Callable [..., Series ],
1469
1470
axis : AxisIndex = ...,
1470
1471
raw : _bool = ...,
1471
1472
args : Any = ...,
1472
1473
* ,
1473
1474
result_type : Literal ["reduce" ],
1474
1475
** kwargs : Any ,
1475
- ) -> Series [ Any ] : ...
1476
+ ) -> Series : ...
1476
1477
1477
1478
# apply() overloads with default result_type of None, and keyword axis=1 matters
1478
1479
@overload
1479
1480
def apply (
1480
1481
self ,
1481
- f : Callable [..., S1 | NAType ],
1482
+ # Use S2 (TypeVar without `default=Any`) instead of S1 due to https://github.com/python/mypy/issues/19182.
1483
+ f : Callable [..., S2 | NAType ],
1482
1484
raw : _bool = ...,
1483
1485
result_type : None = ...,
1484
1486
args : Any = ...,
1485
1487
* ,
1486
1488
axis : AxisColumn ,
1487
1489
** kwargs : Any ,
1488
- ) -> Series [S1 ]: ...
1490
+ ) -> Series [S2 ]: ...
1489
1491
@overload
1490
1492
def apply (
1491
1493
self ,
@@ -1496,11 +1498,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1496
1498
* ,
1497
1499
axis : AxisColumn ,
1498
1500
** kwargs : Any ,
1499
- ) -> Series [ Any ] : ...
1501
+ ) -> Series : ...
1500
1502
@overload
1501
1503
def apply (
1502
1504
self ,
1503
- f : Callable [..., Series [ Any ] ],
1505
+ f : Callable [..., Series ],
1504
1506
raw : _bool = ...,
1505
1507
result_type : None = ...,
1506
1508
args : Any = ...,
@@ -1513,7 +1515,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1513
1515
@overload
1514
1516
def apply (
1515
1517
self ,
1516
- f : Callable [..., Series [ Any ] ],
1518
+ f : Callable [..., Series ],
1517
1519
raw : _bool = ...,
1518
1520
args : Any = ...,
1519
1521
* ,
@@ -1538,7 +1540,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1538
1540
) -> Self : ...
1539
1541
def merge (
1540
1542
self ,
1541
- right : DataFrame | Series [ Any ] ,
1543
+ right : DataFrame | Series ,
1542
1544
how : MergeHow = ...,
1543
1545
on : IndexLabel | AnyArrayLike | None = ...,
1544
1546
left_on : IndexLabel | AnyArrayLike | None = ...,
@@ -1684,6 +1686,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1684
1686
@property
1685
1687
def iloc (self ) -> _iLocIndexerFrame [Self ]: ...
1686
1688
@property
1689
+ # mypy complains if we use Index[Any] instead of UnknownIndex here, even though
1690
+ # the latter is aliased to the former ¯\_(ツ)_/¯.
1687
1691
def index (self ) -> UnknownIndex : ...
1688
1692
@index .setter
1689
1693
def index (self , idx : Index ) -> None : ...
@@ -2012,7 +2016,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
2012
2016
| Callable [[DataFrame ], DataFrame ]
2013
2017
| Callable [[Any ], _bool ]
2014
2018
),
2015
- other : Scalar | UnknownSeries | DataFrame | Callable | NAType | None = ...,
2019
+ other : Scalar | Series | DataFrame | Callable | NAType | None = ...,
2016
2020
* ,
2017
2021
inplace : Literal [True ],
2018
2022
axis : Axis | None = ...,
@@ -2028,7 +2032,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
2028
2032
| Callable [[DataFrame ], DataFrame ]
2029
2033
| Callable [[Any ], _bool ]
2030
2034
),
2031
- other : Scalar | UnknownSeries | DataFrame | Callable | NAType | None = ...,
2035
+ other : Scalar | Series | DataFrame | Callable | NAType | None = ...,
2032
2036
* ,
2033
2037
inplace : Literal [False ] = ...,
2034
2038
axis : Axis | None = ...,
0 commit comments