Skip to content

TYP: type up parts of frame.py #30718

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 2 commits into from
Jan 6, 2020
Merged

Conversation

topper-123
Copy link
Contributor

Type up methods with a single return value type.

@topper-123 topper-123 changed the title TYP: type up frame.py TYP: type up parts of frame.py Jan 5, 2020
@@ -893,10 +897,10 @@ def items(self) -> Iterable[Tuple[Optional[Hashable], Series]]:
yield k, self._ixs(i, axis=1)

@Appender(_shared_docs["items"])
def iteritems(self):
def iteritems(self) -> Iterable[Tuple[Optional[Hashable], Series]]:
Copy link
Member

Choose a reason for hiding this comment

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

Can you create an alias named Label for Optional[Hashable] in pandas._typing and use that instead? I think should help with readability

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've had that thought myself, but I'm starting to have second doubts from a user perspective. E.e. if if an experienced python user sees Optional[Hashable] he knows what that is, but will have to dig into the pandas source code to see what Label means.

Anyway, maybe that can go in a seperate PR?

Copy link
Member

Choose a reason for hiding this comment

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

Fine as a separate PR. We should aim for abstractions where they help clarify the intent of the annotation and I think Label is clearer than Optional[Hashable] in that regards

@@ -7029,7 +7039,7 @@ def append(self, other, ignore_index=False, verify_integrity=False, sort=False):
from pandas.core.reshape.concat import concat

if isinstance(other, (list, tuple)):
to_concat = [self] + other
to_concat = [self] + list(other)
Copy link
Member

Choose a reason for hiding this comment

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

What error was this causing? I'm always hesitant to blanket convert tuples to lists as it can have non-trivial performance impacts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to comment on this: Adding lists and tuples raises a TypeError. It wasn't caught in the tests, but mypy caught it. So a win for static type checking:-)

@WillAyd WillAyd added the Typing type annotations, mypy/pyright type checking label Jan 6, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

@topper-123 lgtm ex @WillAyd comments

Co-Authored-By: Simon Hawkins <[email protected]>
@WillAyd WillAyd added this to the 1.0 milestone Jan 6, 2020
@WillAyd WillAyd merged commit 14f392a into pandas-dev:master Jan 6, 2020
@WillAyd
Copy link
Member

WillAyd commented Jan 6, 2020

Thanks @topper-123

@topper-123 topper-123 deleted the type_frame branch January 6, 2020 19:03
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