Skip to content
Closed
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 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`)
- Bug in ``pd.cut`` (:issue:`14652`)
12 changes: 12 additions & 0 deletions pandas/tools/tests/test_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ def test_series_retbins(self):
np.array([0, 0, 1, 1], dtype=np.int8))
tm.assert_numpy_array_equal(bins, np.array([0, 1.5, 3]))

def test_single_bin(self):
# issue 14652
expected = Series([0, 0])

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

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


def curpath():
pth, _ = os.path.split(os.path.abspath(__file__))
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