@@ -1304,7 +1304,7 @@ def _apply_converter(self, values, conv_f, na_values, col_na_values,
1304
1304
1305
1305
cvals , na_count = self ._infer_types (
1306
1306
values , set (col_na_values ) | col_na_fvalues ,
1307
- try_numeric = False )
1307
+ try_num_bool = False )
1308
1308
return cvals , na_count
1309
1309
1310
1310
def _convert_to_ndarrays (self , dct , na_values , na_fvalues , verbose = False ,
@@ -1331,10 +1331,15 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
1331
1331
values , conv_f , na_values ,
1332
1332
col_na_values , col_na_fvalues )
1333
1333
else :
1334
+ try_num_bool = True
1335
+ if cast_type and is_object_dtype (cast_type ):
1336
+ # skip inference if specified dtype is object
1337
+ try_num_bool = False
1338
+
1334
1339
# general type inference and conversion
1335
1340
cvals , na_count = self ._infer_types (
1336
1341
values , set (col_na_values ) | col_na_fvalues ,
1337
- try_numeric = True )
1342
+ try_num_bool )
1338
1343
1339
1344
if issubclass (cvals .dtype .type , np .integer ) and self .compact_ints :
1340
1345
cvals = lib .downcast_int64 (
@@ -1357,7 +1362,7 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
1357
1362
print ('Filled %d NA values in column %s' % (na_count , str (c )))
1358
1363
return result
1359
1364
1360
- def _infer_types (self , values , na_values , try_numeric = True ):
1365
+ def _infer_types (self , values , na_values , try_num_bool = True ):
1361
1366
na_count = 0
1362
1367
if issubclass (values .dtype .type , (np .number , np .bool_ )):
1363
1368
mask = lib .ismember (values , na_values )
@@ -1368,7 +1373,7 @@ def _infer_types(self, values, na_values, try_numeric=True):
1368
1373
np .putmask (values , mask , np .nan )
1369
1374
return values , na_count
1370
1375
1371
- if try_numeric :
1376
+ if try_num_bool :
1372
1377
try :
1373
1378
result = lib .maybe_convert_numeric (values , na_values , False )
1374
1379
na_count = isnull (result ).sum ()
@@ -1381,7 +1386,7 @@ def _infer_types(self, values, na_values, try_numeric=True):
1381
1386
if values .dtype == np .object_ :
1382
1387
na_count = lib .sanitize_objects (values , na_values , False )
1383
1388
1384
- if result .dtype == np .object_ and try_numeric :
1389
+ if result .dtype == np .object_ and try_num_bool :
1385
1390
result = lib .maybe_convert_bool (values ,
1386
1391
true_values = self .true_values ,
1387
1392
false_values = self .false_values )
0 commit comments