Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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 doc/source/whatsnew/v0.19.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Bug Fixes

- compat with ``dateutil==2.6.0`` for testing (:issue:`14621`)
- allow ``nanoseconds`` in ``Timestamp.replace`` kwargs (:issue:`14621`)
- fix ``pandas.cut`` with one negative value and one bin (:issue:`14652`)
Copy link
Contributor

@jreback jreback Nov 16, 2016

Choose a reason for hiding this comment

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

Bug in pd.cut

15 changes: 15 additions & 0 deletions pandas/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,21 @@ def f():
self.assertFalse(hasattr(t, "b"))


class TestTile(tm.TestCase):

def test_single_bin(self):

expected = pd.Series([0, 0])

s = pd.Series([9., 9.])
Copy link
Contributor

Choose a reason for hiding this comment

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

pandas\tools\tests\test_tile.py

lots of tests there, just add this one on., no need to create a new class. add a comment with the issue number

result = pd.cut(s, 1, labels=False)
tm.assert_series_equal(result, expected)

s = pd.Series([-9., -9.])
result = pd.cut(s, 1, labels=False)
tm.assert_series_equal(result, expected)


if __name__ == '__main__':
import nose

Expand Down
4 changes: 2 additions & 2 deletions pandas/tools/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def cut(x, bins, right=True, labels=None, retbins=False, precision=3,
mn, mx = [mi + 0.0 for mi in rng]

if mn == mx: # adjust end points before binning
mn -= .001 * mn
mx += .001 * mx
mn -= .001 * abs(mn)
mx += .001 * abs(mx)
bins = np.linspace(mn, mx, bins + 1, endpoint=True)
else: # adjust end points after binning
bins = np.linspace(mn, mx, bins + 1, endpoint=True)
Expand Down