Skip to content

Commit 007302d

Browse files
felbrocopybara-github
authored andcommitted
Add the wrapped literal to the display name of kd.literal
If the debug repr is used, the literal currently shows an opaque name making introspection harder. This change aims to make it more clear which value is being shown in order to simplify debugging. Note that for e.g. `repr(kd.expr.literal(kd.slice(1)))`, the pretty print version is shown rather than the debug one, and is not affected by this change. PiperOrigin-RevId: 718262183 Change-Id: I32d7e589c5839bc40db3ab96b8aa8a634fd1de4b
1 parent 4dd0d5c commit 007302d

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

koladata/expr/expr_operators.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "koladata/expr/expr_operators.h"
1616

1717
#include <cstdint>
18+
#include <string>
1819
#include <utility>
1920

2021
#include "absl/status/status.h"
@@ -87,8 +88,8 @@ absl::StatusOr<arolla::expr::ExprAttributes> InputOperator::InferAttributes(
8788

8889
LiteralOperator::LiteralOperator(arolla::TypedValue value)
8990
: arolla::expr::ExprOperatorWithFixedSignature(
90-
"koda_internal.literal", arolla::expr::ExprOperatorSignature{},
91-
"Koda literal.",
91+
absl::StrFormat("koda_internal.literal[%s]", value.Repr()),
92+
arolla::expr::ExprOperatorSignature{}, "Koda literal.",
9293
arolla::FingerprintHasher("::koladata::expr::LiteralOperator")
9394
.Combine(value.GetFingerprint())
9495
.Finish()),

py/koladata/types/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ py_test(
593593
":data_slice",
594594
":literal_operator",
595595
":qtypes",
596-
":schema_constants",
597596
"//py/koladata/expr:view",
598597
"//py/koladata/operators:eager_op_utils",
599598
"//py/koladata/operators:kde_operators",

py/koladata/types/literal_operator_test.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Tests for literal_operator."""
15+
import re
1616

1717
from absl.testing import absltest
1818
from absl.testing import parameterized
@@ -25,7 +25,6 @@
2525
from koladata.types import data_slice
2626
from koladata.types import literal_operator
2727
from koladata.types import qtypes
28-
from koladata.types import schema_constants
2928

3029

3130
kd = eager_op_utils.operators_container('kd')
@@ -144,6 +143,16 @@ def test_literal_operator_init(self):
144143
arolla.eval(op()), arolla.int32(1)
145144
)
146145

146+
def test_op_binding_debug_string(self):
147+
# This uses a debug repr which avoids pretty printing. This ensures that we
148+
# include the wrapped value in the repr.
149+
x = literal_operator.literal(arolla.int32(1))
150+
self.assertEqual(x.op.display_name, 'koda_internal.literal[1]')
151+
with self.assertRaisesRegex(
152+
ValueError, re.escape('koda_internal.literal[1]():INT32')
153+
):
154+
arolla.M.annotation.qtype(x, arolla.FLOAT32)
155+
147156
@parameterized.parameters(
148157
(arolla.L.x,),
149158
(1,),

0 commit comments

Comments
 (0)