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/12/08 17:31:46 UTC

[GitHub] [beam] TheNeuralBit commented on a change in pull request #15944: [BEAM-12563] swaplevel general function for dataframe and series

TheNeuralBit commented on a change in pull request #15944:
URL: https://github.com/apache/beam/pull/15944#discussion_r765077294



##########
File path: sdks/python/apache_beam/dataframe/frames.py
##########
@@ -228,6 +228,16 @@ def droplevel(self, level, axis):
             preserves_partition_by=partitionings.Arbitrary()
             if axis in (1, 'column') else partitionings.Singleton()))
 
+  @frame_base.with_docs_from(pd.DataFrame)
+  @frame_base.args_to_kwargs(pd.DataFrame)
+  def swaplevel(self, **kwargs):
+    return frame_base.DeferredFrame.wrap(
+        expressions.ComputedExpression(
+            'swaplevel',
+            lambda df: df.swaplevel(**kwargs), [self._expr],
+            requires_partition_by=partitionings.Arbitrary(),
+            preserves_partition_by=partitionings.Arbitrary()))

Review comment:
       I wouldn't think this should preserve Index partitioning, since it modifies the index. But our test framework does verify this.
   
   It turns out this expression _does_ preserve index partitioning, since we generate hashes by summing hashes on the individual index levels, which is independent of the order of the index levels.




-- 
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: github-unsubscribe@beam.apache.org

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