anishmehta24 opened a new issue, #40504:
URL: https://github.com/apache/beam/issues/40504

   ### What happened?
   
   With the DataFrame API, `agg` with a list that includes `'count'` or 
`'size'` gives the right numbers, but those rows come back labelled `sum` 
instead of `count`/`size`.
   
   ```python
   import apache_beam as beam
   import numpy as np
   import pandas as pd
   from apache_beam.dataframe.convert import to_dataframe, to_pcollection
   
   pdf = pd.DataFrame({'x': [1.0, np.nan, 3.0], 'y': [10, 20, 30]})
   print(pdf.agg(['count', 'mean']))
   
   with beam.Pipeline() as p:
     df = to_dataframe(p | beam.Create([pdf]), proxy=pdf[:0])
     _ = (
         to_pcollection(
             df.agg(['count', 'mean']),
             include_indexes=True,
             yield_elements='pandas')
         | beam.Map(print))
   ```
   
   pandas:
   
   ```
            x     y
   count  2.0   3.0
   mean   2.0  20.0
   ```
   
   Beam:
   
   ```
           x     y
   sum   2.0   3.0
   mean  2.0  20.0
   ```
   
   `Series.agg(['count'])` and `Series.agg(['size'])` have the same problem.
   
   count and size are computed per partition and then combined with a sum. When 
`func` is a list, `DeferredSeries.aggregate` does that last step with 
`s.agg(['sum'])`, so the row label becomes `sum` 
(sdks/python/apache_beam/dataframe/frames.py, the `agg_func = ['sum'] if 
isinstance(func, list) else 'sum'` line).
   
   Seen on Beam 2.77.0 and on master (7d93ef8e76a), pandas 2.3.3, Python 3.12.
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [x] Component: Python SDK
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to