-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: Overload series/ffill and bfill #41152
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: Overload series/ffill and bfill #41152
Conversation
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.
Thanks Peter, have left some comments
Not too sure about downcast
but that one can always be left out for now and typed later on
pandas/core/generic.py
Outdated
@final | ||
@doc(klass=_shared_doc_kwargs["klass"]) | ||
def ffill( | ||
self: FrameOrSeries, | ||
axis=None, | ||
axis: None | str | int = None, |
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.
axis has it's own type alias, Axis
(check the fillna signature)
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.
Done
pandas/core/generic.py
Outdated
def ffill( | ||
self: FrameOrSeries, | ||
axis: None | str | int = ..., | ||
inplace: Literal[True] = ..., |
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.
this one doesn't need =...
- else, if you call .ffill()
, mypy won't know which overload to match
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.
there also needs to be an extra overload for when axis
isn't passed:
@overload
def ffill(
self: FrameOrSeries,
*,
inplace: Literal[True],
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.
Done
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.
Looks good, thanks! Small comment about the return type in the function itself, other than that looks good to me
pandas/core/generic.py
Outdated
downcast=None, | ||
) -> FrameOrSeries | None: | ||
): |
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 think it should work to keep the return types here, then the function body's return type will be fixed (admittedly this needs fixing in my blog post, will do that now)
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.
Done
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.
Thanks @pckSF !
* TYP: Overload series/ffill and bfill * Resolved comments * Keep the return types
* TYP: Overload series/ffill and bfill * Resolved comments * Keep the return types
Closes part of Function overloads MarcoGorelli/pyladieslondon-sprints#29
Adds
typing.overload
to:ffill
and ``bfill` from https://github.com/pandas-dev/pandas/blob/master/pandas/core/generic.pySetup and Output for
ffill
which results in the following
mypy
output:Setup and Ouput for
bfill
which results in the following
mypy
output: