Skip to content

Commit f37c58f

Browse files
committed
Merge pull request #8896 from pydata/winfix4
COMPAT: windows compat for tests for dtype inference in parser xref (GH8833)
2 parents 0a2ea0a + b8ac6ee commit f37c58f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pandas/io/tests/test_parsers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3173,8 +3173,9 @@ def test_dtype_and_names_error(self):
31733173
tm.assert_frame_equal(result, expected)
31743174

31753175
# fallback casting
3176-
result = self.read_csv(StringIO(data),sep='\s+',header=None,names=['a','b'],dtype={'a' : int})
3176+
result = self.read_csv(StringIO(data),sep='\s+',header=None,names=['a','b'],dtype={'a' : np.int32})
31773177
expected = DataFrame([[1,1],[2,2],[3,3]],columns=['a','b'])
3178+
expected['a'] = expected['a'].astype(np.int32)
31783179
tm.assert_frame_equal(result, expected)
31793180

31803181
data = """
@@ -3184,7 +3185,7 @@ def test_dtype_and_names_error(self):
31843185
"""
31853186
# fallback casting, but not castable
31863187
with tm.assertRaisesRegexp(ValueError, 'cannot safely convert'):
3187-
self.read_csv(StringIO(data),sep='\s+',header=None,names=['a','b'],dtype={'a' : int})
3188+
self.read_csv(StringIO(data),sep='\s+',header=None,names=['a','b'],dtype={'a' : np.int32})
31883189

31893190
def test_fallback_to_python(self):
31903191
# GH 6607

pandas/parser.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ cdef class TextReader:
10601060
if na_count > 0:
10611061
raise Exception('Integer column has NA values')
10621062

1063-
if dtype[1:] != 'i8':
1063+
if result is not None and dtype[1:] != 'i8':
10641064
result = result.astype(dtype)
10651065

10661066
return result, na_count
@@ -1069,7 +1069,7 @@ cdef class TextReader:
10691069
result, na_count = _try_double(self.parser, i, start, end,
10701070
na_filter, na_hashset, na_flist)
10711071

1072-
if dtype[1:] != 'f8':
1072+
if result is not None and dtype[1:] != 'f8':
10731073
result = result.astype(dtype)
10741074
return result, na_count
10751075

0 commit comments

Comments
 (0)