Skip to content

Commit e5fd262

Browse files
committed
ENH: Improve error message for read_csv header argument containing non int types. GH16338.
Adds error "header must be integer or list of integers" when the header argument is a list, tuple or numpy array containing non-integers. Initially intended to read_csv, but applies to other functions with similar header arguments. GH16338 refers to a case in which the user mixes up the "names" and "header" arguments.
1 parent 9da7798 commit e5fd262

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pandas/io/parsers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,8 @@ def __init__(self, kwds):
11641164
# validate header options for mi
11651165
self.header = kwds.get('header')
11661166
if isinstance(self.header, (list, tuple, np.ndarray)):
1167+
if not all(map(is_integer, self.header)):
1168+
raise ValueError("header must be integer or list of integers")
11671169
if kwds.get('as_recarray'):
11681170
raise ValueError("cannot specify as_recarray when "
11691171
"specifying a multi-index header")
@@ -1183,7 +1185,7 @@ def __init__(self, kwds):
11831185
is_integer(self.index_col)):
11841186
raise ValueError("index_col must only contain row numbers "
11851187
"when specifying a multi-index header")
1186-
1188+
11871189
self._name_processed = False
11881190

11891191
self._first_chunk = True

0 commit comments

Comments
 (0)