[tf.data] Set cardinality to UNKNOWN when using ignore_errors transformation.
ignore_errors may cause some elements to be dropped, so we no longer know the exact cardinality. PiperOrigin-RevId: 344875178 Change-Id: I98beadcf8322d5eb23da14192cfeb83e1303e36a
This commit is contained in:
parent
d201930517
commit
cde6ac1b83
@ -64,7 +64,7 @@ class IgnoreErrorsDatasetOp : public UnaryDatasetOpKernel {
|
||||
return "IgnoreErrorsDatasetOp::Dataset";
|
||||
}
|
||||
|
||||
int64 Cardinality() const override { return input_->Cardinality(); }
|
||||
int64 Cardinality() const override { return kUnknownCardinality; }
|
||||
|
||||
Status InputDatasets(
|
||||
std::vector<const DatasetBase*>* inputs) const override {
|
||||
|
@ -161,6 +161,11 @@ class IgnoreErrorsTest(test_base.DatasetTestBase, parameterized.TestCase):
|
||||
with self.assertRaises(errors.OutOfRangeError):
|
||||
self.evaluate(get_next())
|
||||
|
||||
@combinations.generate(test_base.default_test_combinations())
|
||||
def testCardinality(self):
|
||||
ds = dataset_ops.Dataset.range(10).apply(error_ops.ignore_errors())
|
||||
self.assertEqual(self.evaluate(ds.cardinality()), dataset_ops.UNKNOWN)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test.main()
|
||||
|
Loading…
Reference in New Issue
Block a user