Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5544#discussion_r28567346
  
    --- Diff: python/pyspark/sql/dataframe.py ---
    @@ -499,16 +502,37 @@ def sort(self, *cols):
             [Row(age=2, name=u'Alice'), Row(age=5, name=u'Bob')]
             >>> df.orderBy(desc("age"), "name").collect()
             [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
    +        >>> df.orderBy(["age", "name"], ascending=[0, 1]).collect()
    +        [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
             """
             if not cols:
                 raise ValueError("should sort by at least one column")
    -        jcols = ListConverter().convert([_to_java_column(c) for c in cols],
    -                                        self._sc._gateway._gateway_client)
    -        jdf = self._jdf.sort(self._sc._jvm.PythonUtils.toSeq(jcols))
    +        if len(cols) == 1 and isinstance(cols[0], list):
    +            cols = cols[0]
    +        jcols = [_to_java_column(c) for c in cols]
    +        ascending = kwargs.get('ascending', True)
    +        if isinstance(ascending, bool):
    +            if not ascending:
    +                jcols = [jc.desc() for jc in jcols]
    +        elif isinstance(ascending, list):
    +            jcols = [jc if asc else jc.desc()
    +                     for asc, jc in zip(ascending, jcols)]
    +        else:
    +            raise TypeError("ascending can only be bool or list, but got 
%s" % type(ascending))
    +
    +        jdf = self._jdf.sort(self._jseq(jcols))
             return DataFrame(jdf, self.sql_ctx)
     
         orderBy = sort
     
    +    def _jseq(self, cols, converter=None):
    +        return _to_seq(self.sql_ctx._sc, cols, converter)
    --- End diff --
    
    can we add some docstring here to explain what this does?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to