beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rober...@apache.org
Subject [beam] branch master updated: Add __repr__ and disallow __bool__ for DeferredScalar
Date Wed, 10 Mar 2021 07:56:36 GMT
This is an automated email from the ASF dual-hosted git repository.

robertwb 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 4d9c279  Add __repr__ and disallow __bool__ for DeferredScalar
     new 1cd4787  Merge pull request #14181 from TheNeuralBit/deferred-scalard-dunders
4d9c279 is described below

commit 4d9c2792910120645d61897ec5ab5310be832fda
Author: Brian Hulette <bhulette@google.com>
AuthorDate: Tue Mar 9 17:48:33 2021 -0800

    Add __repr__ and disallow __bool__ for DeferredScalar
---
 sdks/python/apache_beam/dataframe/frame_base.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sdks/python/apache_beam/dataframe/frame_base.py b/sdks/python/apache_beam/dataframe/frame_base.py
index ad6e3c2..7674fb2 100644
--- a/sdks/python/apache_beam/dataframe/frame_base.py
+++ b/sdks/python/apache_beam/dataframe/frame_base.py
@@ -111,6 +111,16 @@ class _DeferredScalar(DeferredBase):
               func, [self._expr] + [arg._expr for arg in args],
               requires_partition_by=partitionings.Singleton()))
 
+  def __repr__(self):
+    return f"DeferredScalar[type={type(self._expr.proxy())}]"
+
+  def __bool__(self):
+    # TODO(BEAM-11951): Link to documentation
+    raise TypeError(
+        "Testing the truth value of a deferred scalar is not "
+        "allowed. It's not possible to branch on the result of "
+        "deferred operations.")
+
 
 DeferredBase._pandas_type_map[None] = _DeferredScalar
 


Mime
View raw message