Skip to content

Commit

Permalink
Merge pull request #113 from TomNong/Bytes-conversion-update
Browse files Browse the repository at this point in the history
Fix byte conversion in unit test for compatibility with py2.7
  • Loading branch information
ZhitingHu committed Apr 1, 2019
2 parents 8965934 + c65cc3a commit 194fed3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
11 changes: 6 additions & 5 deletions texar/data/data/multi_aligned_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ def setUp(self):
def _bytes_feature(value):
"""Returns a bytes_list from a string / byte.
"""
if not isinstance(value, (bytes)):
if sys.version_info < (3, 0):
value = bytes(value)
else:
value = bytes(value, 'utf8')
value = tf.compat.as_bytes(
value,
encoding='utf-8'
)
return tf.train.Feature(
bytes_list=tf.train.BytesList(value=[value]))

def _int64_feature(value):
"""Returns an int64_list from a bool / enum / int / uint.
"""
return tf.train.Feature(
int64_list=tf.train.Int64List(value=[value]))

feature = {
"number1": _int64_feature(128),
"number2": _int64_feature(512),
Expand Down
9 changes: 4 additions & 5 deletions texar/data/data/tfrecords_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ def _bytes_feature(value=None):
"""Returns a bytes_list from a string / byte.
"""
# pylint: disable=undefined-loop-variable
if not isinstance(value, (bytes)):
if sys.version_info < (3, 0):
value = bytes(value)
else:
value = bytes(value, 'utf8')
value = tf.compat.as_bytes(
value,
encoding='utf-8'
)
return tf.train.Feature(
bytes_list=tf.train.BytesList(value=[value]))

Expand Down

0 comments on commit 194fed3

Please sign in to comment.