Skip to content

Commit 396c3ab

Browse files
committed
BUG: correct inf/-inf handling in read_csv. close #2041
1 parent 6f02df9 commit 396c3ab

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

RELEASE.rst

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pandas 0.9.1
3737

3838
**Bug fixes**
3939

40+
- Handle inf/-inf correctly in read_* parser functions (#2041)
4041
- Fix matplotlib unicode interaction bug
4142
- Make WLS r-squared match statsmodels 0.5.0 fixed value
4243
- Fix zero-trimming DataFrame formatting bug

pandas/io/tests/test_parsers.py

+9
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ def test_squeeze(self):
196196
self.assert_(isinstance(result, Series))
197197
assert_series_equal(result, expected)
198198

199+
200+
def test_inf_parsing(self):
201+
data = """\
202+
,A
203+
a,inf
204+
b,-inf"""
205+
df = read_csv(StringIO(data), index_col=0)
206+
self.assertTrue(np.isinf(np.abs(df['A'])).all())
207+
199208
def test_multiple_date_col(self):
200209
# Can use multiple date parsers
201210
data = """\

pandas/src/inference.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def maybe_convert_numeric(ndarray[object] values, set na_values,
357357
fval = util.floatify(val)
358358
floats[i] = fval
359359
if not seen_float:
360-
if '.' in val:
360+
if '.' in val or fval == INF or fval == NEGINF:
361361
seen_float = 1
362362
else:
363363
ints[i] = <int64_t> fval

0 commit comments

Comments
 (0)