Skip to content

BUG: Fixed _format_labels in tile.py for np.inf. #4954

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
Sep 25, 2013
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
6 changes: 6 additions & 0 deletions doc/source/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ normally distributed data into equal-size quartiles like so:
factor
value_counts(factor)

We can also pass infinite values to define the bins:
.. ipython:: python

arr = np.random.randn(20)
factor = cut(arr, [-np.inf, 0, np.inf])
factor

.. _basics.apply:

Expand Down
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ Bug Fixes
- Fixed ``copy()`` to shallow copy axes/indices as well and thereby keep
separate metadata. (:issue:`4202`, :issue:`4830`)
- Fixed skiprows option in Python parser for read_csv (:issue:`4382`)
- Fixed bug preventing ``cut`` from working with ``np.inf`` levels without
explicitly passing labels (:issue:`3415`)

pandas 0.12.0
-------------
Expand Down
16 changes: 16 additions & 0 deletions pandas/tools/tests/test_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ def test_na_handling(self):
ex_result = np.where(com.isnull(arr), np.nan, result)
tm.assert_almost_equal(result, ex_result)

def test_inf_handling(self):
data = np.arange(6)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also test with Series? thx

data_ser = Series(data)

result = cut(data, [-np.inf, 2, 4, np.inf])
result_ser = cut(data_ser, [-np.inf, 2, 4, np.inf])

ex_levels = ['(-inf, 2]', '(2, 4]', '(4, inf]']

np.testing.assert_array_equal(result.levels, ex_levels)
np.testing.assert_array_equal(result_ser.levels, ex_levels)
self.assertEquals(result[5], '(4, inf]')
self.assertEquals(result[0], '(-inf, 2]')
self.assertEquals(result_ser[5], '(4, inf]')
self.assertEquals(result_ser[0], '(-inf, 2]')

def test_qcut(self):
arr = np.random.randn(1000)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tools/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _format_label(x, precision=3):
else: # pragma: no cover
return sgn + '.'.join(('%d' % whole, val))
else:
return sgn + '%d' % whole
return sgn + '%0.f' % whole
else:
return str(x)

Expand Down