Skip to content

Commit 01612bf

Browse files
brandonmayertensorflower-gardener
authored andcommitted
Add and test BQ boolean support.
PiperOrigin-RevId: 481679118
1 parent b31812c commit 01612bf

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

tensorflow_gnn/data/unigraph.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,9 @@ def row_to_keyed_example(self, row: Mapping[str, Any]) -> Any:
610610
example_feature = example.features.feature[tf_feature_name]
611611
if feature.dtype == tf.float32.as_datatype_enum:
612612
example_feature.float_list.value.append(feature_value)
613-
elif feature.dtype == tf.int64.as_datatype_enum:
614-
example_feature.int64_list.value.append(feature_value)
613+
elif (feature.dtype == tf.int64.as_datatype_enum or
614+
feature.dtype == tf.bool.as_datatype_enum):
615+
example_feature.int64_list.value.append(int(feature_value))
615616
elif feature.dtype == tf.string.as_datatype_enum:
616617
example_feature.bytes_list.value.append(
617618
row.get(feature_name, "").encode("utf-8"))

tensorflow_gnn/data/unigraph_test.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,24 @@ def test_bigquery_row_to_keyed_example_node_set(self):
188188
dtype: DT_INT64
189189
}
190190
}
191-
features: {
191+
features {
192192
key: "float_feature"
193193
value {
194194
dtype: DT_FLOAT
195195
}
196196
}
197-
features: {
197+
features {
198198
key: "string_feature"
199199
value {
200200
dtype: DT_STRING
201201
}
202202
}
203+
features {
204+
key: "bool_feature"
205+
value {
206+
dtype: DT_BOOL
207+
}
208+
}
203209
metadata {
204210
bigquery {
205211
table_spec {
@@ -224,12 +230,14 @@ def fake_bq_reader(**unused_kwargs):
224230
"id": "id1",
225231
"string_feature": "a",
226232
"float_feature": 1.0,
227-
"int_feature": 2
233+
"int_feature": 2,
234+
"bool_feature": True
228235
}, {
229236
"id": "id2",
230237
"string_feature": "b",
231238
"int_feature": 3,
232-
"float_feature": 4.0
239+
"float_feature": 4.0,
240+
"bool_feature": False
233241
}])
234242

235243
with test_pipeline.TestPipeline() as pipeline:
@@ -277,6 +285,14 @@ def fake_bq_reader(**unused_kwargs):
277285
}
278286
}
279287
}
288+
feature {
289+
key: "bool_feature"
290+
value {
291+
int64_list {
292+
value: 1
293+
}
294+
}
295+
}
280296
}""", tf.train.Example())),
281297
(b"id2",
282298
text_format.Parse(
@@ -313,6 +329,14 @@ def fake_bq_reader(**unused_kwargs):
313329
}
314330
}
315331
}
332+
feature {
333+
key: "bool_feature"
334+
value {
335+
int64_list {
336+
value: 0
337+
}
338+
}
339+
}
316340
}""", tf.train.Example()))]))
317341

318342
def test_bigquery_row_to_keyed_example_edge_set(self):

0 commit comments

Comments
 (0)