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