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

    https://github.com/apache/spark/pull/2094#discussion_r16630361
  
    --- Diff: python/pyspark/rdd.py ---
    @@ -810,23 +810,45 @@ def func(iterator):
     
             return self.mapPartitions(func).fold(zeroValue, combOp)
     
    -    def max(self):
    +    def max(self, comp=None):
             """
             Find the maximum item in this RDD.
     
    -        >>> sc.parallelize([1.0, 5.0, 43.0, 10.0]).max()
    +        @param comp: A function used to compare two elements, the builtin 
`cmp`
    +                     will be used by default.
    +
    +        >>> rdd = sc.parallelize([1.0, 5.0, 43.0, 10.0])
    +        >>> rdd.max()
             43.0
    +        >>> rdd.max(lambda a, b: cmp(str(a), str(b)))
    +        5.0
             """
    -        return self.reduce(max)
    +        if comp is not None:
    +            func = lambda a, b: a if comp(a, b) >= 0 else b
    +        else:
    +            func = max
     
    -    def min(self):
    +        return self.reduce(func)
    +
    +    def min(self, comp=None):
             """
             Find the minimum item in this RDD.
     
    -        >>> sc.parallelize([1.0, 5.0, 43.0, 10.0]).min()
    -        1.0
    +        @param comp: A function used to compare two elements, the builtin 
`cmp`
    +                     will be used by default.
    +
    +        >>> rdd = sc.parallelize([2.0, 5.0, 43.0, 10.0])
    +        >>> rdd.min()
    +        2.0
    +        >>> rdd.min(lambda a, b: cmp(str(a), str(b)))
    +        10.0
             """
    -        return self.reduce(min)
    +        if comp is not None:
    --- End diff --
    
    consider default of comp=min in arg list and test for comp is not min


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