Skip to content

Commit 6644f8b

Browse files
committed
BUG: Fix for to_excel +/- infinity
Previously, a negative sign was being prepended to positive infinite values and was absent for negative infinity. (GH6812) TST: assert_almost_equals() checks +/- infinity The existing ``test_inf_roundtrip`` should have caught this bug, but the underlying ``assert_almost_equal`` was not checking that the two given values were both positive or negative.
1 parent 59c175f commit 6644f8b

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

doc/source/v0.15.0.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,11 @@ Bug Fixes
621621
return a non scalar value that appeared valid but wasn't (:issue:`7870`).
622622
- Bug in ``date_range()``/``DatetimeIndex()`` when the timezone was inferred from input dates yet incorrect
623623
times were returned when crossing DST boundaries (:issue:`7835`, :issue:`7901`).
624-
625-
624+
- Bug in ``to_excel()`` where a negative sign was being prepended to positive infinity and was absent for negative infinity (:issue`7949`)
626625
- Bug in area plot draws legend with incorrect ``alpha`` when ``stacked=True`` (:issue:`8027`)
627-
628626
- ``Period`` and ``PeriodIndex`` addition/subtraction with ``np.timedelta64`` results in incorrect internal representations (:issue:`7740`)
627+
times were returned when crossing DST boundaries (:issue:`7835`, :issue:`7901`).
628+
- Bug in ``to_excel()`` where a negative sign was being prepended to positive infinity and was absent for negative infinity (:issue`7949`)
629629

630630
- ``Holiday`` bug in Holiday with no offset or observance (:issue:`7987`)
631631

pandas/core/format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1512,9 +1512,9 @@ def _format_value(self, val):
15121512
val = self.na_rep
15131513
elif com.is_float(val):
15141514
if np.isposinf(val):
1515-
val = '-%s' % self.inf_rep
1516-
elif np.isneginf(val):
15171515
val = self.inf_rep
1516+
elif np.isneginf(val):
1517+
val = '-%s' % self.inf_rep
15181518
elif self.float_format is not None:
15191519
val = float(self.float_format % val)
15201520
return val

pandas/src/testing.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ cpdef assert_almost_equal(a, b, bint check_less_precise=False):
122122

123123
if np.isinf(a):
124124
assert np.isinf(b), "First object is inf, second isn't"
125+
if np.isposinf(a):
126+
assert np.isposinf(b), "First object is positive inf, second is negative inf"
127+
else:
128+
assert np.isneginf(b), "First object is negative inf, second is positive inf"
125129
else:
126130
fa, fb = a, b
127131

0 commit comments

Comments
 (0)