You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/01/19 18:54:23 UTC

[GitHub] [beam] robertwb commented on a change in pull request #13637: [BEAM-11542] Add support for projecting GroupBy objects

robertwb commented on a change in pull request #13637:
URL: https://github.com/apache/beam/pull/13637#discussion_r560405869



##########
File path: sdks/python/apache_beam/dataframe/frames.py
##########
@@ -1503,10 +1506,32 @@ def unstack(self, *args, **kwargs):
 
 @populate_not_implemented(pd.core.groupby.generic.DataFrameGroupBy)
 class DeferredGroupBy(frame_base.DeferredFrame):
-  def __init__(self, expr, kwargs):
+  def __init__(self, expr, kwargs,
+               ungrouped: DeferredDataFrameOrSeries, projection=None):
     super(DeferredGroupBy, self).__init__(expr)
+    # This object represents the result of:
+    # ungrouped.groupby(level=list(range(ungrouped.index.nlevels),
+    #                   **kwargs)[projection]
+    self._ungrouped = ungrouped
+    self._projection = projection
     self._kwargs = kwargs
 
+  def __getattr__(self, name):
+    return DeferredGroupBy(expressions.ComputedExpression(
+        'groupby_project',
+        lambda gb: getattr(gb, name), [self._expr],
+        requires_partition_by=partitionings.Nothing(),
+        preserves_partition_by=partitionings.Singleton()),
+                           self._kwargs, self._ungrouped, name)

Review comment:
       This indentation seems odd. Perhaps add a newline after the DeferredGroupBy above? 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org