Skip to content

Commit abc6e41

Browse files
cavenesstf-data-validation-team
caveness
authored and
tf-data-validation-team
committed
no-op
PiperOrigin-RevId: 272678863
1 parent 71dc7d8 commit abc6e41

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

tensorflow_data_validation/statistics/generators/image_stats_generator_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_image_stats_generator_disable_size_stats(self):
327327

328328
def _read_file(filepath):
329329
"""Helper method for reading a file in binary mode."""
330-
f = tf.gfile.Open(filepath, mode='rb')
330+
f = tf.io.gfile.GFile(filepath, mode='rb')
331331
return f.read()
332332

333333

tensorflow_data_validation/utils/stats_gen_lib.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def generate_statistics_from_tfrecord(
8787
if output_path is None:
8888
output_path = os.path.join(tempfile.mkdtemp(), 'data_stats.tfrecord')
8989
output_dir_path = os.path.dirname(output_path)
90-
if not tf.gfile.Exists(output_dir_path):
91-
tf.gfile.MakeDirs(output_dir_path)
90+
if not tf.io.gfile.exists(output_dir_path):
91+
tf.io.gfile.makedirs(output_dir_path)
9292

9393
batch_size = (
9494
stats_options.desired_batch_size if stats_options.desired_batch_size
@@ -162,8 +162,8 @@ def generate_statistics_from_csv(
162162
if output_path is None:
163163
output_path = os.path.join(tempfile.mkdtemp(), 'data_stats.tfrecord')
164164
output_dir_path = os.path.dirname(output_path)
165-
if not tf.gfile.Exists(output_dir_path):
166-
tf.gfile.MakeDirs(output_dir_path)
165+
if not tf.io.gfile.exists(output_dir_path):
166+
tf.io.gfile.makedirs(output_dir_path)
167167

168168
batch_size = (
169169
stats_options.desired_batch_size if stats_options.desired_batch_size
@@ -318,13 +318,13 @@ def get_csv_header(data_location: Text,
318318
ValueError: If any of the input files is not found or empty, or if the files
319319
have different headers.
320320
"""
321-
matched_files = tf.gfile.Glob(data_location)
321+
matched_files = tf.io.gfile.glob(data_location)
322322
if not matched_files:
323323
raise ValueError(
324324
'No file found in the input data location: %s' % data_location)
325325

326326
# Read the header line in the first file.
327-
with tf.gfile.GFile(matched_files[0], 'r') as reader:
327+
with tf.io.gfile.GFile(matched_files[0], 'r') as reader:
328328
try:
329329
result = next(csv.reader(reader, delimiter=delimiter))
330330
except StopIteration:
@@ -333,7 +333,7 @@ def get_csv_header(data_location: Text,
333333

334334
# Make sure that all files have the same header.
335335
for filename in matched_files[1:]:
336-
with tf.gfile.GFile(filename, 'r') as reader:
336+
with tf.io.gfile.GFile(filename, 'r') as reader:
337337
try:
338338
if next(csv.reader(reader, delimiter=delimiter)) != result:
339339
raise ValueError('Files have different headers.')
@@ -354,7 +354,7 @@ def load_statistics(
354354
Returns:
355355
A DatasetFeatureStatisticsList proto.
356356
"""
357-
serialized_stats = next(tf.python_io.tf_record_iterator(input_path))
357+
serialized_stats = next(tf.compat.v1.io.tf_record_iterator(input_path))
358358
result = statistics_pb2.DatasetFeatureStatisticsList()
359359
result.ParseFromString(serialized_stats)
360360
return result

tensorflow_data_validation/utils/stats_gen_lib_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _make_example(self, feature_name_to_type_values_tuple_map):
8181

8282
def _write_tfexamples_to_tfrecords(self, examples, compression_type):
8383
data_location = os.path.join(self._get_temp_dir(), 'input_data.tfrecord')
84-
with tf.python_io.TFRecordWriter(
84+
with tf.io.TFRecordWriter(
8585
data_location, options=compression_type) as writer:
8686
for example in examples:
8787
writer.write(example.SerializeToString())
@@ -115,8 +115,11 @@ def test_stats_gen_with_tfrecords_of_tfexamples(self, compression_type):
115115
})
116116
]
117117
tf_compression_lookup = {
118-
CompressionTypes.AUTO: tf.io.TFRecordCompressionType.NONE,
119-
CompressionTypes.GZIP: tf.io.TFRecordCompressionType.GZIP}
118+
CompressionTypes.AUTO:
119+
tf.compat.v1.python_io.TFRecordCompressionType.NONE,
120+
CompressionTypes.GZIP:
121+
tf.compat.v1.python_io.TFRecordCompressionType.GZIP
122+
}
120123
input_data_path = self._write_tfexamples_to_tfrecords(
121124
examples, tf_compression_lookup[compression_type])
122125

tensorflow_data_validation/utils/validation_lib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def validate_examples_in_tfrecord(
8383
if output_path is None:
8484
output_path = os.path.join(tempfile.mkdtemp(), 'anomaly_stats.tfrecord')
8585
output_dir_path = os.path.dirname(output_path)
86-
if not tf.gfile.Exists(output_dir_path):
87-
tf.gfile.MakeDirs(output_dir_path)
86+
if not tf.io.gfile.exists(output_dir_path):
87+
tf.io.gfile.makedirs(output_dir_path)
8888

8989
with beam.Pipeline(options=pipeline_options) as p:
9090
_ = (
@@ -161,8 +161,8 @@ def validate_examples_in_csv(
161161
if output_path is None:
162162
output_path = os.path.join(tempfile.mkdtemp(), 'anomaly_stats.tfrecord')
163163
output_dir_path = os.path.dirname(output_path)
164-
if not tf.gfile.Exists(output_dir_path):
165-
tf.gfile.MakeDirs(output_dir_path)
164+
if not tf.io.gfile.exists(output_dir_path):
165+
tf.io.gfile.makedirs(output_dir_path)
166166

167167
# If a header is not provided, assume the first line in a file
168168
# to be the header.

tensorflow_data_validation/utils/validation_lib_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_validate_examples_in_tfrecord(self):
8989

9090
temp_dir_path = self.create_tempdir().full_path
9191
input_data_path = os.path.join(temp_dir_path, 'input_data.tfrecord')
92-
with tf.python_io.TFRecordWriter(input_data_path) as writer:
92+
with tf.io.TFRecordWriter(input_data_path) as writer:
9393
for example in input_examples:
9494
example = text_format.Parse(example, tf.train.Example())
9595
writer.write(example.SerializeToString())

0 commit comments

Comments
 (0)