Skip to content

TYP: Enable mypy stricter typing for defs/calls #54271

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 7 commits into from
Jul 27, 2023

Conversation

mroeschke
Copy link
Member

No description provided.

@mroeschke mroeschke added the Typing type annotations, mypy/pyright type checking label Jul 26, 2023
@mroeschke mroeschke requested a review from twoertwein July 26, 2023 21:20
@mroeschke mroeschke added this to the 2.1 milestone Jul 26, 2023
@@ -82,7 +87,7 @@ def select_columns(self, indices) -> PandasDataFrameXchg:
self._df.iloc[:, indices], self._nan_as_null, self._allow_copy
)

def select_columns_by_name(self, names) -> PandasDataFrameXchg:
def select_columns_by_name(self, names: Sequence[str]) -> PandasDataFrameXchg:
Copy link
Member

Choose a reason for hiding this comment

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

This would allow str @Dr-Irv , does it work for a string at runtime?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so. I think it's intended to accept a list-like of strings, but I just matched the base class here. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you only want to accept a list of strings, you have to use list[str]. If you use Sequence[str] then an argument of "abc" would match

pandas/io/gbq.py Outdated
@@ -215,7 +215,7 @@ def to_gbq(
table_schema: list[dict[str, str]] | None = None,
location: str | None = None,
progress_bar: bool = True,
credentials=None,
credentials: Any = None,
Copy link
Member

Choose a reason for hiding this comment

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

The documentation says, it needs to be google.auth.credentials.Credentials | None

Copy link
Member

Choose a reason for hiding this comment

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

(but if the CI doesn't install the package, there is not much benefit of importing it in a TYPE_CHECKING block.)

Copy link
Member

@twoertwein twoertwein left a comment

Choose a reason for hiding this comment

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

Thank you for enforcing type annotations @mroeschke !

I left a few suggestions to avoid Any but would also be fine to merge already.

cc @Dr-Irv

Copy link
Contributor

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

I think the only thing to change is to use list[str] instead of Sequence[str] in that one place

@@ -87,7 +87,7 @@ def select_columns(self, indices: Sequence[int]) -> PandasDataFrameXchg:
self._df.iloc[:, indices], self._nan_as_null, self._allow_copy
)

def select_columns_by_name(self, names: Sequence[str]) -> PandasDataFrameXchg:
def select_columns_by_name(self, names: list[str]) -> PandasDataFrameXchg: # type: ignore[override] # noqa: E501
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty interesting that you have to do the override. In some sense, the method DataFrameXchg.select_columns_by_name() is wrong when it says names is Sequence[str], because probably the people who wrote that aren't aware that a pure str will match.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this might be an oversight on the original spec. I opened an issue regarding this data-apis/dataframe-api#212

@mroeschke mroeschke merged commit 7b48899 into pandas-dev:main Jul 27, 2023
@mroeschke mroeschke deleted the typ/mypy/strict_def branch July 27, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants