Skip to content

Commit ffd8301

Browse files
zoyahavtfx-copybara
authored andcommitted
Update tests now that earliest supported TF version persists sparse tensor dense shapes
PiperOrigin-RevId: 546904332
1 parent 51a5e95 commit ffd8301

File tree

2 files changed

+25
-41
lines changed

2 files changed

+25
-41
lines changed

tensorflow_transform/beam/impl_test.py

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4425,22 +4425,18 @@ def test3dSparseWithTFXIO(self):
44254425
feature {
44264426
name: "x$sparse_indices_0"
44274427
type: INT
4428-
# TODO(b/184055743): Once TensorFlow is released with
4429-
# cl/514884437, uncomment.
4430-
# int_domain {
4431-
# min: 0
4432-
# max: 4
4433-
# }
4428+
int_domain {
4429+
min: 0
4430+
max: 4
4431+
}
44344432
}
44354433
feature {
44364434
name: "x$sparse_indices_1"
44374435
type: INT
4438-
# TODO(b/184055743): Once TensorFlow is released with
4439-
# cl/514884437 uncomment.
4440-
# int_domain {
4441-
# min: 0
4442-
# max: 4
4443-
# }
4436+
int_domain {
4437+
min: 0
4438+
max: 4
4439+
}
44444440
}
44454441
feature {
44464442
name: "x$sparse_values"
@@ -4458,29 +4454,20 @@ def test3dSparseWithTFXIO(self):
44584454
value_feature {
44594455
name: "x$sparse_values"
44604456
}
4461-
}""", schema_pb2.Schema())
4457+
}""",
4458+
schema_pb2.Schema(),
4459+
)
44624460
if not tft_unit.is_external_environment():
44634461
expected_metadata.generate_legacy_feature_spec = False
44644462

4465-
# TODO(b/184055743): Once TensorFlow is released with cl/514884437,
4466-
# remove this.
4467-
def int_domain_cleared(schema):
4468-
result = schema_pb2.Schema()
4469-
result.CopyFrom(schema)
4470-
for f in result.feature:
4471-
f.ClearField('int_domain')
4472-
return result
4473-
4474-
self.assertProtoEquals(int_domain_cleared(transformed_metadata.schema),
4475-
expected_metadata)
4463+
self.assertProtoEquals(transformed_metadata.schema, expected_metadata)
44764464

44774465
beam_test_util.assert_that(
44784466
transformed_data, self._MakeTransformOutputAssertFn(expected_data))
44794467

44804468
def _assert_schemas_equal_fn(schema_dict_list):
44814469
self.assertEqual(1, len(schema_dict_list))
4482-
self.assertProtoEquals(
4483-
int_domain_cleared(schema_dict_list[0].schema), expected_metadata)
4470+
self.assertProtoEquals(schema_dict_list[0].schema, expected_metadata)
44844471

44854472
beam_test_util.assert_that(
44864473
transformed_metadata.deferred_metadata,
@@ -4493,18 +4480,16 @@ def _assert_schemas_equal_fn(schema_dict_list):
44934480
transformed_feature_spec = tft_out.transformed_feature_spec()
44944481
self.assertLen(transformed_feature_spec, 1)
44954482
self.assertIn('x', transformed_feature_spec)
4496-
self.assertIn(
4483+
self.assertEqual(
44974484
transformed_feature_spec['x'],
4498-
(tf.io.SparseFeature(['x$sparse_indices_0', 'x$sparse_indices_1'],
4499-
'x$sparse_values',
4500-
tf.float32, [5, 5],
4501-
already_sorted=True),
4502-
# TODO(b/184055743): Once TensorFlow is released with cl/514884437,
4503-
# remove this.
4504-
tf.io.SparseFeature(['x$sparse_indices_0', 'x$sparse_indices_1'],
4505-
'x$sparse_values',
4506-
tf.float32, [-1, -1],
4507-
already_sorted=True)))
4485+
tf.io.SparseFeature(
4486+
['x$sparse_indices_0', 'x$sparse_indices_1'],
4487+
'x$sparse_values',
4488+
tf.float32,
4489+
[5, 5],
4490+
already_sorted=True,
4491+
),
4492+
)
45084493

45094494
transformed_feature_spec['x'] = tf.io.SparseFeature(
45104495
['x$sparse_indices_0', 'x$sparse_indices_1'],

tensorflow_transform/impl_helper_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,9 @@ def test_batched_placeholders_from_typespecs(self):
725725
self.assertEqual(features['dense_string'].dtype, tf.string)
726726

727727
self.assertEqual(type(features['_sparse_underscored']), tf.SparseTensor)
728-
# TODO(b/184055743): Once TensorFlow is released with cl/514884437,
729-
# only keep the assertion of [None, None, 17].
730-
self.assertIn(features['_sparse_underscored'].get_shape().as_list(),
731-
([None, None, 17], [None, None, None]))
728+
self.assertEqual(
729+
features['_sparse_underscored'].get_shape().as_list(), [None, None, 17]
730+
)
732731
self.assertEqual(features['_sparse_underscored'].dtype, tf.string)
733732

734733
self.assertEqual(type(features['ragged_string']), tf.RaggedTensor)

0 commit comments

Comments
 (0)