You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by al...@apache.org on 2020/03/24 20:19:53 UTC
[beam] branch master updated: [BEAM-9579] Fix numpy logic operators
(#11204)
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 <kr...@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