Skip to content

PERF: fast inf checking in to_excel #11352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions asv_bench/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"numexpr": [],
"pytables": [],
"openpyxl": [],
"xlsxwriter": [],
"xlrd": [],
"xlwt": []
},
Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.17.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Performance Improvements
- Release the GIL on most datetime field operations (e.g. ``DatetimeIndex.year``, ``Series.dt.year``), normalization, and conversion to and from ``Period``, ``DatetimeIndex.to_period`` and ``PeriodIndex.to_timestamp`` (:issue:`11263`)


- Improved performance to ``to_excel`` (:issue:`11352`)

.. _whatsnew_0171.bug_fixes:

Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1708,9 +1708,9 @@ def _format_value(self, val):
if lib.checknull(val):
val = self.na_rep
elif com.is_float(val):
if np.isposinf(val):
if lib.isposinf_scalar(val):
val = self.inf_rep
elif np.isneginf(val):
elif lib.isneginf_scalar(val):
val = '-%s' % self.inf_rep
elif self.float_format is not None:
val = float(self.float_format % val)
Expand Down
12 changes: 12 additions & 0 deletions pandas/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ cpdef checknull_old(object val):
else:
return util._checknull(val)

cpdef isposinf_scalar(object val):
if util.is_float_object(val) and val == INF:
return True
else:
return False

cpdef isneginf_scalar(object val):
if util.is_float_object(val) and val == NEGINF:
return True
else:
return False

def isscalar(object val):
"""
Return True if given value is scalar.
Expand Down
15 changes: 14 additions & 1 deletion pandas/tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ def test_maybe_indices_to_slice_middle(self):
self.assert_numpy_array_equal(maybe_slice, indices)
self.assert_numpy_array_equal(target[indices], target[maybe_slice])

def test_isinf_scalar(self):
#GH 11352
self.assertTrue(lib.isposinf_scalar(float('inf')))
self.assertTrue(lib.isposinf_scalar(np.inf))
self.assertFalse(lib.isposinf_scalar(-np.inf))
self.assertFalse(lib.isposinf_scalar(1))
self.assertFalse(lib.isposinf_scalar('a'))

self.assertTrue(lib.isneginf_scalar(float('-inf')))
self.assertTrue(lib.isneginf_scalar(-np.inf))
self.assertFalse(lib.isneginf_scalar(np.inf))
self.assertFalse(lib.isneginf_scalar(1))
self.assertFalse(lib.isneginf_scalar('a'))

class Testisscalar(tm.TestCase):

Expand Down Expand Up @@ -232,4 +245,4 @@ def test_lisscalar_pandas_containers(self):
import nose

nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
exit=False)
exit=False)