This is an automated email from the ASF dual-hosted git repository.

claudevdm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d3bc627199 [Python] Keep the Series name in DataFrame Series.agg with 
a list (#40573)
1d3bc627199 is described below

commit 1d3bc6271994f7c6a3ea5ddbb89b5def400a2ef3
Author: Anish Mehta <[email protected]>
AuthorDate: Thu Oct 15 00:00:00 2026 +0530

    [Python] Keep the Series name in DataFrame Series.agg with a list (#40573)
---
 sdks/python/apache_beam/dataframe/frames.py      | 4 +++-
 sdks/python/apache_beam/dataframe/frames_test.py | 6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/sdks/python/apache_beam/dataframe/frames.py 
b/sdks/python/apache_beam/dataframe/frames.py
index 500152f4490..4b62fed72f0 100644
--- a/sdks/python/apache_beam/dataframe/frames.py
+++ b/sdks/python/apache_beam/dataframe/frames.py
@@ -2057,11 +2057,13 @@ class DeferredSeries(DeferredDataFrameOrSeries):
       if base_func in HAND_IMPLEMENTED_GLOBAL_AGGREGATIONS:
         result = getattr(self, base_func)(*args, **kwargs)
         if isinstance(func, list):
+          name = self._expr.proxy().name
           with expressions.allow_non_parallel_operations(True):
             return frame_base.DeferredFrame.wrap(
                 expressions.ComputedExpression(
                     f'wrap_aggregate_{base_func}',
-                    lambda x: pd.Series(x, index=[base_func]), [result._expr],
+                    lambda x: pd.Series(x, index=[base_func], name=name),
+                    [result._expr],
                     requires_partition_by=partitionings.Singleton(),
                     preserves_partition_by=partitionings.Singleton()))
         else:
diff --git a/sdks/python/apache_beam/dataframe/frames_test.py 
b/sdks/python/apache_beam/dataframe/frames_test.py
index 67f61aa68c6..00400045200 100644
--- a/sdks/python/apache_beam/dataframe/frames_test.py
+++ b/sdks/python/apache_beam/dataframe/frames_test.py
@@ -2190,6 +2190,12 @@ class AggregationTest(_AbstractFrameTest):
     self._run_test(lambda s: s.agg(['mean']), s)
     self._run_test(lambda s: s.agg('mean'), s)
 
+  def test_series_agg_list_keeps_name(self):
+    s = pd.Series(list(range(16)), name='x')
+    self._run_test(lambda s: s.agg(['mean']), s)
+    self._run_test(lambda s: s.agg(['sum', 'mean']), s)
+    self._run_test(lambda s: s.agg(['std', 'var']), s)
+
   def test_dataframe_agg_modes(self):
     df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [2, 3, 5, 7]})
     self._run_test(lambda df: df.agg('sum'), df)

Reply via email to