Skip to content

Commit

Permalink
MAINT: Use set logic to check dups
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung committed Aug 30, 2017
1 parent b2b19f4 commit 869e363
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def _validate_integer(name, val, min_val=0):
return val


def _check_dup_names(names):
def _validate_names(names):
"""
Check if the `names` parameter contains duplicates.
Expand All @@ -395,25 +395,20 @@ def _check_dup_names(names):
----------
names : array-like or None
An array containing a list of the names used for the output DataFrame.
"""

if names is None:
return
counts = {}
warn_dups = False

for name in names:
if name in counts:
warn_dups = True
break
Returns
-------
names : array-like or None
The original `names` parameter.
"""

counts[name] = True
if names is not None:
if len(names) != len(set(names)):
msg = ("Duplicate names specified. This "
"will raise an error in the future.")
warnings.warn(msg, FutureWarning, stacklevel=3)

if warn_dups:
msg = ("Duplicate names specified. This "
"will raise an error in the future.")
warnings.warn(msg, FutureWarning, stacklevel=3)
return names


def _read(filepath_or_buffer, kwds):
Expand All @@ -439,8 +434,7 @@ def _read(filepath_or_buffer, kwds):
nrows = _validate_integer('nrows', kwds.get('nrows', None))

# Check for duplicates in names.
names = kwds.get("names", None)
_check_dup_names(names)
names = _validate_names(kwds.get("names", None))

# Create the parser.
parser = TextFileReader(filepath_or_buffer, **kwds)
Expand Down

0 comments on commit 869e363

Please sign in to comment.