Skip to content
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

BUG: regression in DataFrame.transform('func') #19760

Closed
jorisvandenbossche opened this issue Feb 19, 2018 · 0 comments
Closed

BUG: regression in DataFrame.transform('func') #19760

jorisvandenbossche opened this issue Feb 19, 2018 · 0 comments
Labels
Apply Apply, Aggregate, Transform, Map Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Feb 19, 2018

From a failing example in the doc build (http://pandas-docs.github.io/pandas-docs-travis/basics.html#transform-api):

tsdf = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'],
                    index=pd.date_range('1/1/2000', periods=10))
tsdf.iloc[3:7] = np.nan

Using a numpy func directly is fine:

In [43]: tsdf.transform(np.abs)
Out[43]: 
                   A         B         C
2000-01-01  1.038786  0.380848  1.190139
2000-01-02  2.201640  0.004028  0.704541
2000-01-03  1.803344  0.774565  0.034836
2000-01-04       NaN       NaN       NaN
2000-01-05       NaN       NaN       NaN
2000-01-06       NaN       NaN       NaN
2000-01-07       NaN       NaN       NaN
2000-01-08  0.351827  0.265785  1.424491
2000-01-09  0.962042  1.291740  1.107973
2000-01-10  0.366717  0.318791  0.117215

But specifying the function with a string now breaks:

In [44]: tsdf.transform('abs')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-44-405a88736ee3> in <module>()
----> 1 tsdf.transform('abs')

/home/joris/scipy/pandas/pandas/core/generic.py in transform(self, func, *args, **kwargs)
   7694         @Appender(_shared_docs['transform'] % _shared_doc_kwargs)
   7695         def transform(self, func, *args, **kwargs):
-> 7696             result = self.agg(func, *args, **kwargs)
   7697             if is_scalar(result) or len(result) != len(self):
   7698                 raise ValueError("transforms cannot produce "

/home/joris/scipy/pandas/pandas/core/frame.py in aggregate(self, func, axis, *args, **kwargs)
   4830                 pass
   4831         if result is None:
-> 4832             return self.apply(func, axis=axis, args=args, **kwargs)
   4833         return result
   4834 

/home/joris/scipy/pandas/pandas/core/frame.py in apply(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds)
   5020                          args=args,
   5021                          kwds=kwds)
-> 5022         return op.get_result()
   5023 
   5024     def applymap(self, func):

/home/joris/scipy/pandas/pandas/core/apply.py in get_result(self)
    309                                       *self.args, **self.kwds)
    310 
--> 311         return super(FrameRowApply, self).get_result()
    312 
    313     def apply_broadcast(self):

/home/joris/scipy/pandas/pandas/core/apply.py in get_result(self)
    113         if isinstance(self.f, compat.string_types):
    114             self.kwds['axis'] = self.axis
--> 115             return getattr(self.obj, self.f)(*self.args, **self.kwds)
    116 
    117         # ufunc

TypeError: abs() got an unexpected keyword argument 'axis'

This is on master, while it was working in 0.22 (tested with the same version of numpy, 1.13)

@jorisvandenbossche jorisvandenbossche added Regression Functionality that used to work in a prior pandas version Apply Apply, Aggregate, Transform, Map labels Feb 19, 2018
@jorisvandenbossche jorisvandenbossche added this to the 0.23.0 milestone Feb 19, 2018
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Apr 23, 2018
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Apr 23, 2018
@jreback jreback modified the milestones: 0.23.0, 0.23.1 Apr 24, 2018
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.23.1, 0.23.0 Apr 24, 2018
TomAugspurger added a commit that referenced this issue Apr 25, 2018
* BUG: Fixed NDFrame.transform('abs')

Closes #19760
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

No branches or pull requests

2 participants