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

TYP/TST: tests/mypy complaints failing locally #52423

Merged
merged 5 commits into from
Apr 7, 2023
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
1 change: 1 addition & 0 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3129,6 +3129,7 @@ def _nth(
dropped = self.obj.dropna(how=dropna, axis=self.axis)

# get a new grouper for our dropped obj
grouper: np.ndarray | Index | ops.BaseGrouper
if self.keys is None and self.level is None:
# we don't have the grouper info available
# (e.g. we have selected out
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/io/test_clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import numpy as np
import pytest

from pandas.compat import is_ci_environment
from pandas.compat import (
is_ci_environment,
is_platform_mac,
)
from pandas.errors import (
PyperclipException,
PyperclipWindowsException,
Expand Down Expand Up @@ -401,7 +404,8 @@ def test_round_trip_valid_encodings(self, enc, df):
@pytest.mark.single_cpu
@pytest.mark.parametrize("data", ["\U0001f44d...", "Ωœ∑´...", "abcd..."])
@pytest.mark.xfail(
os.environ.get("DISPLAY") is None or is_ci_environment(),
(os.environ.get("DISPLAY") is None and not is_platform_mac())
or is_ci_environment(),
reason="Cannot pass if a headless system is not put in place with Xvfb",
strict=not is_ci_environment(), # Flaky failures in the CI
)
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/io/xml/test_to_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,9 @@ def test_stylesheet_file_like(datapath, mode):
def test_stylesheet_io(datapath, mode):
xsl_path = datapath("io", "data", "xml", "row_field_output.xsl")

xsl_obj: BytesIO | StringIO
# note: By default the bodies of untyped functions are not checked,
# consider using --check-untyped-defs
xsl_obj: BytesIO | StringIO # type: ignore[annotation-unchecked]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def test_stylesheet_io(datapath, mode) -> None: for mypy to check this function and not emit this note

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for test_dirname_mixin, for the others produces error: Untyped decorator makes function "test_stylesheet_io" untyped [misc]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether the following is worth it: could lie about skip_if_no

def skip_if_no(package: str, min_version: str | None = None): -> Callable[[F], F]: ...

A simpler version could just be to remove those xsl_obj: BytesIO | StringIO lines - they are not used by mypy/pyright anyways.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully this can be handled correctly upstream pytest-dev/pytest#7469


with open(xsl_path, mode) as f:
if mode == "rb":
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/io/xml/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,9 @@ def test_stylesheet_io(datapath, mode):
kml = datapath("io", "data", "xml", "cta_rail_lines.kml")
xsl = datapath("io", "data", "xml", "flatten_doc.xsl")

xsl_obj: BytesIO | StringIO
# note: By default the bodies of untyped functions are not checked,
# consider using --check-untyped-defs
xsl_obj: BytesIO | StringIO # type: ignore[annotation-unchecked]

with open(xsl, mode) as f:
if mode == "rb":
Expand Down Expand Up @@ -1349,7 +1351,9 @@ def test_stylesheet_file_close(datapath, mode):
kml = datapath("io", "data", "xml", "cta_rail_lines.kml")
xsl = datapath("io", "data", "xml", "flatten_doc.xsl")

xsl_obj: BytesIO | StringIO
# note: By default the bodies of untyped functions are not checked,
# consider using --check-untyped-defs
xsl_obj: BytesIO | StringIO # type: ignore[annotation-unchecked]

with open(xsl, mode) as f:
if mode == "rb":
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_register_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pandas.core import accessor


def test_dirname_mixin():
def test_dirname_mixin() -> None:
# GH37173

class X(accessor.DirNamesMixin):
Expand Down