Skip to content

Named aggregation doesn't work in DataFrame.agg #2305

@gshimansky

Description

@gshimansky

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):

Ubuntu 19.10

  • Modin version (modin.__version__):

0.8.1.1+31.ga0a3ebb

  • Python version:

Python 3.8.3

  • Code we can use to reproduce:
import numpy as np
import modin.pandas as pd
#import pandas as pd

df = pd.DataFrame({
    "col1": [ 1,  2,  1,  2,  1,  3,  3,  2,  3],
    "col2": [11, 12, 13, 14, 15, 16, 17, 18, 19],
    "col3": [ 4,  4,  4,  4,  5,  5,  5,  5,  5],
    "col4": [ 1,  1,  1,  1,  1,  1,  1,  1,  1]
})
print(df, '\n')

df1 = df.agg(new_col=('col2', max))
print(df1, '\n')
df2 = df.agg(new_col1=('col2', 'max'), new_col2=('col2', 'min'), new_col3=('col2', 'sum'),
              new_col4=('col4', 'max'), new_col5=('col4', 'min'), new_col6=('col4', 'sum'))
print(df2, '\n')

Describe the problem

Running this code results in an exception:

Traceback (most recent call last):
  File "agg_test2.py", line 13, in <module>
    df1 = df.agg(new_col=('col2', max))
  File "/localdisk/gashiman/modin/modin/pandas/base.py", line 504, in aggregate
    return self.apply(func, axis=axis, args=args, **kwargs)
  File "/localdisk/gashiman/modin/modin/pandas/dataframe.py", line 289, in apply
    query_compiler = super(DataFrame, self).apply(
  File "/localdisk/gashiman/modin/modin/pandas/base.py", line 716, in apply
    raise TypeError("{} object is not callable".format(type(func)))
TypeError: <class 'NoneType'> object is not callable

This bug may be related to how named aggregation worked in groupby before #2254 was fixed.

Source code / logs

Metadata

Metadata

Assignees

Labels

bug 🦗Something isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions