diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index 7b8bdeb1f38b8..228dad984bb3c 100644 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -3173,8 +3173,9 @@ def test_dtype_and_names_error(self): tm.assert_frame_equal(result, expected) # fallback casting - result = self.read_csv(StringIO(data),sep='\s+',header=None,names=['a','b'],dtype={'a' : int}) + result = self.read_csv(StringIO(data),sep='\s+',header=None,names=['a','b'],dtype={'a' : np.int32}) expected = DataFrame([[1,1],[2,2],[3,3]],columns=['a','b']) + expected['a'] = expected['a'].astype(np.int32) tm.assert_frame_equal(result, expected) data = """ @@ -3184,7 +3185,7 @@ def test_dtype_and_names_error(self): """ # fallback casting, but not castable with tm.assertRaisesRegexp(ValueError, 'cannot safely convert'): - self.read_csv(StringIO(data),sep='\s+',header=None,names=['a','b'],dtype={'a' : int}) + self.read_csv(StringIO(data),sep='\s+',header=None,names=['a','b'],dtype={'a' : np.int32}) def test_fallback_to_python(self): # GH 6607 diff --git a/pandas/parser.pyx b/pandas/parser.pyx index eb80a51728765..afaa5219ab0cd 100644 --- a/pandas/parser.pyx +++ b/pandas/parser.pyx @@ -1060,7 +1060,7 @@ cdef class TextReader: if na_count > 0: raise Exception('Integer column has NA values') - if dtype[1:] != 'i8': + if result is not None and dtype[1:] != 'i8': result = result.astype(dtype) return result, na_count @@ -1069,7 +1069,7 @@ cdef class TextReader: result, na_count = _try_double(self.parser, i, start, end, na_filter, na_hashset, na_flist) - if dtype[1:] != 'f8': + if result is not None and dtype[1:] != 'f8': result = result.astype(dtype) return result, na_count