Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test setter on df.columns with pyright, not mypy #484

Merged
merged 1 commit into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ types-pytz = ">= 2022.1.1"
mypy = "0.991"
pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = ">=1.1.284"
pyright = ">=1.1.286"
poethepoet = "0.16.0"
loguru = ">=0.6.0"
pandas = "1.5.2"
Expand Down Expand Up @@ -171,6 +171,7 @@ strict_equality = true
show_error_context = false
show_column_numbers = false
show_error_codes = true
always_true = "IS_TYPE_CHECKER_MYPY"

[tool.pyright]
typeCheckingMode = "strict"
Expand All @@ -192,3 +193,5 @@ reportUnusedVariable = false
reportPrivateUsage = false
# enable optional checks
reportMissingModuleSource = true
defineConstant = { IS_TYPE_CHECKER_MYPY = false }

1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
PD_LTE_15 = Version(pd.__version__) < Version("1.5.999")
IS_TYPE_CHECKER_MYPY = True

lxml_skip = pytest.mark.skipif(
sys.version_info >= (3, 11), reason="lxml is not available for 3.11 yet"
Expand Down
25 changes: 14 additions & 11 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from pandas._typing import Scalar

from tests import (
IS_TYPE_CHECKER_MYPY,
PD_LTE_15,
TYPE_CHECKING_INVALID_USAGE,
check,
Expand Down Expand Up @@ -1775,18 +1776,20 @@ def test_iloc_tuple() -> None:
def test_set_columns() -> None:
# GH 73
df = pd.DataFrame({"a": [1, 2, 3], "b": [0.0, 1, 1]})
# Next line should work, but it is a mypy bug
# Next lines should work, but it is a mypy bug
# https://github.com/python/mypy/issues/3004
# pyright doesn't need the ignore
df.columns = ["c", "d"] # type: ignore[assignment]
df.columns = [1, 2] # type: ignore[assignment]
df.columns = [1, "a"] # type: ignore[assignment]
df.columns = np.array([1, 2]) # type: ignore[assignment]
df.columns = pd.Series([1, 2]) # type: ignore[assignment]
df.columns = np.array([1, "a"]) # type: ignore[assignment]
df.columns = pd.Series([1, "a"]) # type: ignore[assignment]
df.columns = (1, 2) # type: ignore[assignment]
df.columns = (1, "a") # type: ignore[assignment]
# pyright accepts this, so we only type check for pyright,
# and also test the code with pytest
if (TYPE_CHECKING and not IS_TYPE_CHECKER_MYPY) or not TYPE_CHECKING:
df.columns = ["c", "d"]
df.columns = [1, 2]
df.columns = [1, "a"]
df.columns = np.array([1, 2])
df.columns = pd.Series([1, 2])
df.columns = np.array([1, "a"])
df.columns = pd.Series([1, "a"])
df.columns = (1, 2)
df.columns = (1, "a")


def test_frame_index_numpy() -> None:
Expand Down