|
40 | 40 | Never, |
41 | 41 | Self, |
42 | 42 | TypeAlias, |
43 | | - assert_never, |
44 | 43 | assert_type, |
45 | 44 | ) |
46 | 45 | import xarray as xr |
@@ -3503,47 +3502,39 @@ def test_diff() -> None: |
3503 | 3502 | BaseOffset, |
3504 | 3503 | index_to_check_for_type=-1, |
3505 | 3504 | ) |
3506 | | - # bool -> object |
| 3505 | + # bool -> Any |
3507 | 3506 | check( |
3508 | 3507 | assert_type( |
3509 | | - pd.Series([True, True, False, False, True]).diff(), |
3510 | | - "pd.Series[type[object]]", |
| 3508 | + pd.Series([True, True, False, False, True]).diff(), "pd.Series[Any]" |
3511 | 3509 | ), |
3512 | 3510 | pd.Series, |
3513 | 3511 | object, |
3514 | 3512 | ) |
3515 | | - # object -> object |
3516 | | - check( |
3517 | | - assert_type(s.astype(object).diff(), "pd.Series[type[object]]"), |
3518 | | - pd.Series, |
3519 | | - object, |
3520 | | - ) |
| 3513 | + # Any -> float |
| 3514 | + s_o = s.astype(object) |
| 3515 | + assert_type(s_o, "pd.Series[Any]") |
| 3516 | + check(assert_type(s_o.diff(), "pd.Series[float]"), pd.Series, float) |
3521 | 3517 | # complex -> complex |
3522 | 3518 | check( |
3523 | 3519 | assert_type(s.astype(complex).diff(), "pd.Series[complex]"), pd.Series, complex |
3524 | 3520 | ) |
3525 | | - if TYPE_CHECKING_INVALID_USAGE: |
3526 | | - # interval -> TypeError: IntervalArray has no 'diff' method. Convert to a suitable dtype prior to calling 'diff'. |
3527 | | - assert_never(pd.Series([pd.Interval(0, 2), pd.Interval(1, 4)]).diff()) |
3528 | 3521 |
|
| 3522 | + def _diff_invalid0(): # pyright: ignore[reportUnusedFunction] |
| 3523 | + # interval -> TypeError: IntervalArray has no 'diff' method. Convert to a suitable dtype prior to calling 'diff'. |
| 3524 | + assert_type(pd.Series([pd.Interval(0, 2), pd.Interval(1, 4)]).diff(), Never) |
3529 | 3525 |
|
3530 | | -def test_diff_never1() -> None: |
3531 | | - s = pd.Series([1, 1, 2, 3, 5, 8]) |
3532 | | - if TYPE_CHECKING_INVALID_USAGE: |
| 3526 | + def _diff_invalid1() -> None: # pyright: ignore[reportUnusedFunction] |
| 3527 | + s = pd.Series([1, 1, 2, 3, 5, 8]) |
3533 | 3528 | # bytes -> numpy.core._exceptions._UFuncNoLoopError: ufunc 'subtract' did not contain a loop with signature matching types (dtype('S21'), dtype('S21')) -> None |
3534 | | - assert_never(s.astype(bytes).diff()) |
3535 | | - |
| 3529 | + s.astype(bytes).diff() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] |
3536 | 3530 |
|
3537 | | -def test_diff_never2() -> None: |
3538 | | - if TYPE_CHECKING_INVALID_USAGE: |
| 3531 | + def _diff_invalid2() -> None: # pyright: ignore[reportUnusedFunction] |
3539 | 3532 | # dtype -> TypeError: unsupported operand type(s) for -: 'type' and 'type' |
3540 | | - assert_never(pd.Series([str, int, bool]).diff()) |
3541 | | - |
| 3533 | + pd.Series([str, int, bool]).diff() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] |
3542 | 3534 |
|
3543 | | -def test_diff_never3() -> None: |
3544 | | - if TYPE_CHECKING_INVALID_USAGE: |
| 3535 | + def _diff_invalid3() -> None: # pyright: ignore[reportUnusedFunction] |
3545 | 3536 | # str -> TypeError: unsupported operand type(s) for -: 'str' and 'str' |
3546 | | - assert_never(pd.Series(["a", "b"]).diff()) |
| 3537 | + pd.Series(["a", "b"]).diff() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] |
3547 | 3538 |
|
3548 | 3539 |
|
3549 | 3540 | def test_operator_constistency() -> None: |
|
0 commit comments