@@ -341,7 +341,7 @@ def parser_f(filepath_or_buffer,
341
341
squeeze = False ,
342
342
mangle_dupe_cols = True ,
343
343
tupleize_cols = False ,
344
- ):
344
+ factorize = True ):
345
345
346
346
# Alias sep -> delimiter.
347
347
if delimiter is None :
@@ -401,7 +401,7 @@ def parser_f(filepath_or_buffer,
401
401
buffer_lines = buffer_lines ,
402
402
mangle_dupe_cols = mangle_dupe_cols ,
403
403
tupleize_cols = tupleize_cols ,
404
- )
404
+ factorize = factorize )
405
405
406
406
return _read (filepath_or_buffer , kwds )
407
407
@@ -490,35 +490,34 @@ def _get_options_with_defaults(self, engine):
490
490
kwds = self .orig_options
491
491
492
492
options = {}
493
- for argname , default in compat .iteritems (_parser_defaults ):
494
- if argname in kwds :
495
- value = kwds [argname ]
496
- else :
497
- value = default
498
493
499
- options [argname ] = value
494
+ for argname , default in compat .iteritems (_parser_defaults ):
495
+ options [argname ] = kwds .get (argname , default )
500
496
501
497
for argname , default in compat .iteritems (_c_parser_defaults ):
502
498
if argname in kwds :
503
499
value = kwds [argname ]
500
+
504
501
if engine != 'c' and value != default :
505
- raise ValueError ('%s is not supported with %s parser' %
506
- (argname , engine ))
502
+ raise ValueError ('The %r option is not supported with the'
503
+ ' %r engine' % (argname , engine ))
504
+ else :
505
+ value = default
507
506
options [argname ] = value
508
507
509
508
if engine == 'python-fwf' :
510
509
for argname , default in compat .iteritems (_fwf_defaults ):
511
- if argname in kwds :
512
- value = kwds [argname ]
513
- options [argname ] = value
510
+ options [argname ] = kwds .get (argname , default )
514
511
515
512
return options
516
513
517
514
def _clean_options (self , options , engine ):
518
515
result = options .copy ()
519
516
520
517
sep = options ['delimiter' ]
521
- if (sep is None and not options ['delim_whitespace' ]):
518
+ delim_whitespace = options ['delim_whitespace' ]
519
+
520
+ if sep is None and not delim_whitespace :
522
521
if engine == 'c' :
523
522
print ('Using Python parser to sniff delimiter' )
524
523
engine = 'python'
@@ -667,21 +666,24 @@ def __init__(self, kwds):
667
666
self .header = kwds .get ('header' )
668
667
if isinstance (self .header ,(list ,tuple ,np .ndarray )):
669
668
if kwds .get ('as_recarray' ):
670
- raise Exception ("cannot specify as_recarray when "
671
- "specifying a multi-index header" )
669
+ raise ValueError ("cannot specify as_recarray when "
670
+ "specifying a multi-index header" )
672
671
if kwds .get ('usecols' ):
673
- raise Exception ("cannot specify usecols when "
674
- "specifying a multi-index header" )
672
+ raise ValueError ("cannot specify usecols when "
673
+ "specifying a multi-index header" )
675
674
if kwds .get ('names' ):
676
- raise Exception ("cannot specify names when "
677
- "specifying a multi-index header" )
675
+ raise ValueError ("cannot specify names when "
676
+ "specifying a multi-index header" )
678
677
679
678
# validate index_col that only contains integers
680
679
if self .index_col is not None :
681
- if not (isinstance (self .index_col ,(list ,tuple ,np .ndarray )) and all (
682
- [ com .is_integer (i ) for i in self .index_col ]) or com .is_integer (self .index_col )):
683
- raise Exception ("index_col must only contain row numbers "
684
- "when specifying a multi-index header" )
680
+ is_sequence = isinstance (self .index_col , (list , tuple ,
681
+ np .ndarray ))
682
+ if not (is_sequence and
683
+ all (com .is_integer (i ) for i in self .index_col ) or
684
+ com .is_integer (self .index_col )):
685
+ raise ValueError ("index_col must only contain row numbers "
686
+ "when specifying a multi-index header" )
685
687
686
688
self ._name_processed = False
687
689
0 commit comments