Skip to content

Commit 9c76ba6

Browse files
authored
cherry-pick data_feeder bug fix to 1.6 (#20840)
* test=document_fix * test=release/1.6
1 parent 4841474 commit 9c76ba6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

python/paddle/fluid/data_feeder.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@
2727

2828

2929
def convert_dtype(dtype):
30-
if isinstance(dtype, str):
31-
if dtype in [
32-
'bool', 'float16', 'float32', 'float64', 'int8', 'int16',
33-
'int32', 'int64', 'uint8'
34-
]:
35-
return dtype
36-
else:
30+
if isinstance(dtype, core.VarDesc.VarType):
3731
if dtype == core.VarDesc.VarType.BOOL:
3832
return 'bool'
3933
elif dtype == core.VarDesc.VarType.FP16:
@@ -52,6 +46,19 @@ def convert_dtype(dtype):
5246
return 'int64'
5347
elif dtype == core.VarDesc.VarType.UINT8:
5448
return 'uint8'
49+
else:
50+
if dtype in [
51+
'bool', 'float16', 'float32', 'float64', 'int8', 'int16',
52+
'int32', 'int64', 'uint8', u'bool', u'float16', u'float32',
53+
u'float64', u'int8', u'int16', u'int32', u'int64', u'uint8'
54+
]:
55+
# this code is a little bit dangerous, since error could happen
56+
# when casting no-asci code to str in python2.
57+
# but since the set itself is limited, so currently, it is good.
58+
# however, jointly supporting python2 and python3, (as well as python4 maybe)
59+
# may still be a long-lasting problem.
60+
return str(dtype)
61+
5562
raise ValueError(
5663
"dtype must be any of [bool, float16, float32, float64, int8, int16, "
5764
"int32, int64, uint8]")

0 commit comments

Comments
 (0)