Skip to content

Commit

Permalink
pandas-dev#34946 Check type of names argument to read_csv, `read_ta…
Browse files Browse the repository at this point in the history
…ble`, `read_fwf` to not be a `set`.
  • Loading branch information
MJafarMashhadi committed Jun 23, 2020
1 parent 477fed5 commit 44a71b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def _validate_integer(name, val, min_val=0):

def _validate_names(names):
"""
Raise ValueError if the `names` parameter contains duplicates.
Raise ValueError if the `names` parameter contains duplicates or has an invalid data type.
Parameters
----------
Expand All @@ -407,11 +407,13 @@ def _validate_names(names):
Raises
------
ValueError
If names are not unique.
If names are not unique or have incosistent ordering (e.g. set).
"""
if names is not None:
if len(names) != len(set(names)):
raise ValueError("Duplicate names are not allowed.")
if not is_list_like(names, allow_sets=False):
raise ValueError("Names should have consistent ordering. Consider a list instead.")


def _read(filepath_or_buffer: FilePathOrBuffer, kwds):
Expand Down

0 comments on commit 44a71b9

Please sign in to comment.