Skip to content

TYP: func argument to DataFrame.apply, DataFrame.applymap, core.apply.frame_apply #38493

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 9 commits into from
Dec 18, 2020

Conversation

arw2019
Copy link
Member

@arw2019 arw2019 commented Dec 15, 2020

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Spinning off from #38416, xref #38416 (comment)

@@ -7656,7 +7658,13 @@ def transform(
return result

def apply(
self, func, axis: Axis = 0, raw: bool = False, result_type=None, args=(), **kwds
self,
func: ApplyFuncType,
Copy link
Member

@jorisvandenbossche jorisvandenbossche Dec 15, 2020

Choose a reason for hiding this comment

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

Just to make it explicit, this annotation will show up as Union[np.ufunc, Union[Callable, str, List[Union[Callable, str]], Dict[Union[Hashable, NoneType], Union[Callable, str, List[Union[Callable, str]]]]]]

(kind of unreadable, IMO, but so which is not even complete yet, since the ufunc should be present in each nested case Union[Callable, str]. But isn't a ufunc a callable, so that can maybe be removed?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Going off the aggregation case we don't special case ufunc there so we probably shouldn't do it here either.

In that case I think ApplyFuncType is the same as AggFuncType so we can use the same alias in both cases

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah i agree here, no need to be different, let's use AggFuncType

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -7656,7 +7658,13 @@ def transform(
return result

def apply(
self, func, axis: Axis = 0, raw: bool = False, result_type=None, args=(), **kwds
self,
func: ApplyFuncType,
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah i agree here, no need to be different, let's use AggFuncType

@jreback jreback added the Typing type annotations, mypy/pyright type checking label Dec 16, 2020
@jreback jreback added this to the 1.3 milestone Dec 18, 2020
@jreback jreback merged commit b578be4 into pandas-dev:master Dec 18, 2020
@jreback
Copy link
Contributor

jreback commented Dec 18, 2020

thanks @arw2019

luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
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