@@ -384,7 +384,7 @@ def _validate_integer(name, val, min_val=0):
384
384
return val
385
385
386
386
387
- def _check_dup_names (names ):
387
+ def _validate_names (names ):
388
388
"""
389
389
Check if the `names` parameter contains duplicates.
390
390
@@ -395,25 +395,20 @@ def _check_dup_names(names):
395
395
----------
396
396
names : array-like or None
397
397
An array containing a list of the names used for the output DataFrame.
398
- """
399
-
400
- if names is None :
401
- return
402
398
403
- counts = {}
404
- warn_dups = False
405
-
406
- for name in names :
407
- if name in counts :
408
- warn_dups = True
409
- break
399
+ Returns
400
+ -------
401
+ names : array-like or None
402
+ The original `names` parameter.
403
+ """
410
404
411
- counts [name ] = True
405
+ if names is not None :
406
+ if len (names ) != len (set (names )):
407
+ msg = ("Duplicate names specified. This "
408
+ "will raise an error in the future." )
409
+ warnings .warn (msg , FutureWarning , stacklevel = 3 )
412
410
413
- if warn_dups :
414
- msg = ("Duplicate names specified. This "
415
- "will raise an error in the future." )
416
- warnings .warn (msg , FutureWarning , stacklevel = 3 )
411
+ return names
417
412
418
413
419
414
def _read (filepath_or_buffer , kwds ):
@@ -440,7 +435,7 @@ def _read(filepath_or_buffer, kwds):
440
435
441
436
# Check for duplicates in names.
442
437
names = kwds .get ("names" , None )
443
- _check_dup_names (names )
438
+ _validate_names (names )
444
439
445
440
# Create the parser.
446
441
parser = TextFileReader (filepath_or_buffer , ** kwds )
0 commit comments