Skip to content

Fix typing errors #29114

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

Merged
merged 1 commit into from
Oct 20, 2019
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
7 changes: 5 additions & 2 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def coerce(request):
(iter([1, 2]), True, "iterator"), # noqa: E241
(iter([]), True, "iterator-empty"), # noqa: E241
((x for x in [1, 2]), True, "generator"), # noqa: E241
((x for x in []), True, "generator-empty"), # noqa: E241
((_ for _ in []), True, "generator-empty"), # noqa: E241
(Series([1]), True, "Series"), # noqa: E241
(Series([]), True, "Series-empty"), # noqa: E241
(Series(["a"]).str, True, "StringMethods"), # noqa: E241
Expand Down Expand Up @@ -288,7 +288,10 @@ class MockFile:
assert not is_file(data)


@pytest.mark.parametrize("ll", [collections.namedtuple("Test", list("abc"))(1, 2, 3)])
test_tuple = collections.namedtuple("Test", ["a", "b", "c"])
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity is there any issue you saw that suggested doing this? I don't think its evident why this would need to exist without knowing the context of this PR.

If it is an issue with mypy or typeshed would sometimes prefer to wait for a fix upstream; generally not in a rush with these

Copy link
Contributor Author

@AbhijeetKrishnan AbhijeetKrishnan Oct 21, 2019

Choose a reason for hiding this comment

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

mypy does not infer that the collections.namedtuple() call returns a class of user-defined type. It, for some reason, assumes that it returns a tuple. tuple() expects an argument of Iterable[Any], which is why we see the error pandas\tests\dtypes\test_inference.py:291: error: Argument 1 to "tuple" has incompatible type "int"; expected "Iterable[Any]".

mypy also does not seem to infer that list('abc') is a literal of type List[str]. The error doesn't show up if the above one isn't corrected, but if you change ['a', 'b', 'c'] to list('abc') in the committed code, then you get the error pandas/tests/dtypes/test_inference.py:291: error: List or tuple literal expected as the second argument to namedtuple(). mypy does infer that ['a', 'b', 'c'] is of type List[str].

IMO these do seem to be limitations in mypy.

Copy link
Member

Choose a reason for hiding this comment

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

OK thanks for confirming. It would be good for future edits in this project and the entire python eco-system as a whole if those were raised as issues with MyPy, if not already

Not saying this was a problem merging, but especially for internal-only annotations like this there is no rush. If something like that is raised with MyPy and looks like it would be available in a few releases would rather wait than making code edits here

Copy link
Contributor Author

Choose a reason for hiding this comment

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



@pytest.mark.parametrize("ll", [test_tuple(1, 2, 3)])
def test_is_names_tuple_passes(ll):
assert inference.is_named_tuple(ll)

Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ ignore_errors=True
[mypy-pandas.tests.dtypes.test_common]
ignore_errors=True

[mypy-pandas.tests.dtypes.test_inference]
ignore_errors=True

[mypy-pandas.tests.extension.decimal.test_decimal]
ignore_errors=True

Expand Down