Skip to content

Commit 829e9e5

Browse files
committed
BUG: sql int column with null should result in f8 dtype
1 parent 3646247 commit 829e9e5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas/io/tests/test_parsers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ def test_convert_sql_column_ints(self):
241241
assert_same_values_and_dtype(result, expected)
242242
assert_same_values_and_dtype(result2, expected)
243243

244+
arr = np.array([1, 2, 3, None, 4], dtype='O')
245+
result = lib.convert_sql_column(arr)
246+
expected = np.array([1, 2, 3, np.nan, 4], dtype='f8')
247+
assert_same_values_and_dtype(result, expected)
248+
244249
def test_convert_sql_column_bools(self):
245250
arr = np.array([True, False, True, False], dtype='O')
246251
result = lib.convert_sql_column(arr)

pandas/src/parsing.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ def convert_sql_column(ndarray[object] objects):
135135
floats[i] = val
136136
seen_float = 1
137137
elif not (cpython.PyString_Check(val) or cpython.PyUnicode_Check(val)):
138+
# this will convert Decimal objects
138139
try:
139140
floats[i] = float(val)
140141
seen_float = 1
141142
except Exception:
142143
pass
143144

144145
if seen_null:
145-
if seen_float:
146+
if seen_float or seen_int:
146147
return floats
147148
else:
148149
return objects

0 commit comments

Comments
 (0)