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



##########
File path: sdks/python/apache_beam/dataframe/frames.py
##########
@@ -922,6 +922,20 @@ def mask(self, cond, **kwargs):
     """mask is not parallelizable when ``errors="ignore"`` is specified."""
     return self.where(~cond, **kwargs)
 
+  @frame_base.with_docs_from(pd.DataFrame)
+  @frame_base.args_to_kwargs(pd.DataFrame)
+  @frame_base.populate_defaults(pd.DataFrame)
+  def truncate(self, before, after, axis):
+
+    return frame_base.DeferredFrame.wrap(
+        expressions.ComputedExpression(
+            'truncate',
+            lambda df:
+            (df.sort_index() if axis in (None, 0, 'index') else df).truncate(
+                before=before, after=after, axis=axis), [self._expr],

Review comment:
       nit: it would be preferable not to check the axis inside this function. 
We know what axis is at pipeline construction time, so we don't need to branch 
for every element. You could do something like this instead:
   
   ```py
   if axis in (None, 0, 'index'):
     def truncate(df):
       df.sort_index().truncate(before=before, after=after, axis=axis)
   else:
     def truncate(df):
       df.truncate(before=before, after=after, axis=axis)
   ```
   
   Then here you would do:
   ```suggestion
               lambda df:
               truncate, [self._expr],
   ```




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