|
38 | 38 | from pandas._typing import Scalar
|
39 | 39 |
|
40 | 40 | from tests import (
|
| 41 | + IS_TYPE_CHECKER_MYPY, |
41 | 42 | PD_LTE_15,
|
42 | 43 | TYPE_CHECKING_INVALID_USAGE,
|
43 | 44 | check,
|
@@ -1775,18 +1776,20 @@ def test_iloc_tuple() -> None:
|
1775 | 1776 | def test_set_columns() -> None:
|
1776 | 1777 | # GH 73
|
1777 | 1778 | df = pd.DataFrame({"a": [1, 2, 3], "b": [0.0, 1, 1]})
|
1778 |
| - # Next line should work, but it is a mypy bug |
| 1779 | + # Next lines should work, but it is a mypy bug |
1779 | 1780 | # https://github.com/python/mypy/issues/3004
|
1780 |
| - # pyright doesn't need the ignore |
1781 |
| - df.columns = ["c", "d"] # type: ignore[assignment] |
1782 |
| - df.columns = [1, 2] # type: ignore[assignment] |
1783 |
| - df.columns = [1, "a"] # type: ignore[assignment] |
1784 |
| - df.columns = np.array([1, 2]) # type: ignore[assignment] |
1785 |
| - df.columns = pd.Series([1, 2]) # type: ignore[assignment] |
1786 |
| - df.columns = np.array([1, "a"]) # type: ignore[assignment] |
1787 |
| - df.columns = pd.Series([1, "a"]) # type: ignore[assignment] |
1788 |
| - df.columns = (1, 2) # type: ignore[assignment] |
1789 |
| - df.columns = (1, "a") # type: ignore[assignment] |
| 1781 | + # pyright accepts this, so we only type check for pyright, |
| 1782 | + # and also test the code with pytest |
| 1783 | + if (TYPE_CHECKING and not IS_TYPE_CHECKER_MYPY) or not TYPE_CHECKING: |
| 1784 | + df.columns = ["c", "d"] |
| 1785 | + df.columns = [1, 2] |
| 1786 | + df.columns = [1, "a"] |
| 1787 | + df.columns = np.array([1, 2]) |
| 1788 | + df.columns = pd.Series([1, 2]) |
| 1789 | + df.columns = np.array([1, "a"]) |
| 1790 | + df.columns = pd.Series([1, "a"]) |
| 1791 | + df.columns = (1, 2) |
| 1792 | + df.columns = (1, "a") |
1790 | 1793 |
|
1791 | 1794 |
|
1792 | 1795 | def test_frame_index_numpy() -> None:
|
|
0 commit comments