Skip to content

Commit 826b076

Browse files
TomAugspurgerjorisvandenbossche
authored andcommitted
[Backport pandas-dev#14657] COMPAT: Cast to string before raise in read_stata (pandas-dev#14657)
Fix ValueError message in StataReader Cast to string before joining the list of typecodes in the error message. (cherry picked from commit 1606153)
1 parent a0c4637 commit 826b076

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/io/stata.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1210,18 +1210,18 @@ def _read_old_header(self, first_char):
12101210
if tp in self.OLD_TYPE_MAPPING:
12111211
typlist.append(self.OLD_TYPE_MAPPING[tp])
12121212
else:
1213-
typlist.append(tp - 127) # string
1213+
typlist.append(tp - 127) # py2 string, py3 bytes
12141214

12151215
try:
12161216
self.typlist = [self.TYPE_MAP[typ] for typ in typlist]
12171217
except:
12181218
raise ValueError("cannot convert stata types [{0}]"
1219-
.format(','.join(typlist)))
1219+
.format(','.join(str(x) for x in typlist)))
12201220
try:
12211221
self.dtyplist = [self.DTYPE_MAP[typ] for typ in typlist]
12221222
except:
12231223
raise ValueError("cannot convert stata dtypes [{0}]"
1224-
.format(','.join(typlist)))
1224+
.format(','.join(str(x) for x in typlist)))
12251225

12261226
if self.format_version > 108:
12271227
self.varlist = [self._null_terminate(self.path_or_buf.read(33))

0 commit comments

Comments
 (0)