Skip to content

BUG: Fix DataFrame.apply for string arg with additional args (#22376) #22377

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 5 commits into from
Aug 23, 2018
Merged

BUG: Fix DataFrame.apply for string arg with additional args (#22376) #22377

merged 5 commits into from
Aug 23, 2018

Conversation

megabyde
Copy link
Contributor

@megabyde megabyde commented Aug 16, 2018


result = self.frame.apply(arg, axis=1)
expected = getattr(self.frame, arg)(axis=1)
@pytest.mark.parametrize('kwds', [{}, {'axis': 1}, {'numeric_only': True}])
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a test for just std that adds both a positional arg (e.g. ddof) and a kwarg (numeric_only) for confirmation here (and other combinations if possible)

@@ -71,7 +71,8 @@ def __init__(self, obj, func, broadcast, raw, reduce, result_type,
self.result_type = result_type

# curry if needed
if kwds or args and not isinstance(func, np.ufunc):
if (kwds or args) and not isinstance(func, (np.ufunc,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you format this like

if ((kwds or args) and
    (not isinstance.....)):

Copy link
Contributor Author

@megabyde megabyde Aug 16, 2018

Choose a reason for hiding this comment

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

@jreback The formatting you propose makes Flake complaining:

E129 visually indented line with same indent as next logical line

@jreback jreback added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Numeric Operations Arithmetic, Comparison, and Logical operations labels Aug 16, 2018
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

can you also see if we have tests like this for groupby.apply

@codecov
Copy link

codecov bot commented Aug 16, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@e7fca91). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #22377   +/-   ##
=========================================
  Coverage          ?   92.05%           
=========================================
  Files             ?      169           
  Lines             ?    50709           
  Branches          ?        0           
=========================================
  Hits              ?    46679           
  Misses            ?     4030           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.46% <100%> (?)
#single 42.25% <100%> (?)
Impacted Files Coverage Δ
pandas/core/apply.py 96.75% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7fca91...48d283a. Read the comment docs.

@megabyde
Copy link
Contributor Author

@jreback I checked and GroupBy.apply doesn't support string func arguments with positional args or keywords so seems like nothing to test there in this PR, see

raise ValueError('func must be a callable if args or '

@jreback jreback added this to the 0.24.0 milestone Aug 23, 2018
@jreback jreback merged commit 982f309 into pandas-dev:master Aug 23, 2018
@jreback
Copy link
Contributor

jreback commented Aug 23, 2018

thanks @megabyde

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame.apply fails for string function arguments with additional positional or keyword arguments
2 participants