-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Conversation
@@ -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]]: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
pandas/core/frame.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:-)
There was a problem hiding this 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]>
Thanks @topper-123 |
Type up methods with a single return value type.