Skip to content

Commit

Permalink
Merge pull request #4954 from filmor/format-labels-fix
Browse files Browse the repository at this point in the history
BUG: Fixed _format_labels in tile.py for np.inf.
  • Loading branch information
jreback committed Sep 25, 2013
2 parents a11e143 + 166f907 commit fac7d1d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
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)
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

0 comments on commit fac7d1d

Please sign in to comment.