beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [beam] branch master updated: [BEAM-9579] Fix numpy logic operators (#11204)
Date Tue, 24 Mar 2020 20:19:53 GMT
This is an automated email from the ASF dual-hosted git repository.

altay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 1713b24  [BEAM-9579] Fix numpy logic operators (#11204)
1713b24 is described below

commit 1713b241c5f897017e86dd440bdf3d9b9b3e4c0c
Author: Chris Gorgolewski <krzysztof.gorgolewski@gmail.com>
AuthorDate: Tue Mar 24 13:19:37 2020 -0700

    [BEAM-9579] Fix numpy logic operators (#11204)
    
    [BEAM-9579] Fix numpy logic operators (#11204)
---
 CHANGES.md                                  |  1 +
 sdks/python/apache_beam/transforms/stats.py | 18 ++++++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index ea94b87..39104ea 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -116,6 +116,7 @@
 
 ## Bugfixes
 
+* Fixed numpy operators in ApproximateQuantiles (Python) ([BEAM-9579](https://issues.apache.org/jira/browse/BEAM-9579)).
 * Fixed exception when running in IPython notebook (Python) ([BEAM-X9277](https://issues.apache.org/jira/browse/BEAM-9277)).
 * Fixed 1833 (Python) ([BEAM-1833](https://issues.apache.org/jira/browse/BEAM-1833))
 
diff --git a/sdks/python/apache_beam/transforms/stats.py b/sdks/python/apache_beam/transforms/stats.py
index da94257..fd51f7a 100644
--- a/sdks/python/apache_beam/transforms/stats.py
+++ b/sdks/python/apache_beam/transforms/stats.py
@@ -429,12 +429,18 @@ class ApproximateQuantilesCombineFn(CombineFn):
 
   def __init__(
       self, num_quantiles, buffer_size, num_buffers, key=None, reverse=False):
-    if key:
-      self._comparator = lambda a, b: (key(a) < key(b)) - (key(a) > key(b)) \
-        if reverse else (key(a) > key(b)) - (key(a) < key(b))
-    else:
-      self._comparator = lambda a, b: (a < b) - (a > b) if reverse \
-        else (a > b) - (a < b)
+    def _comparator(a, b):
+      if key:
+        a, b = key(a), key(b)
+
+      retval = int(a > b) - int(a < b)
+
+      if reverse:
+        return -retval
+
+      return retval
+
+    self._comparator = _comparator
 
     self._num_quantiles = num_quantiles
     self._buffer_size = buffer_size


Mime
View raw message