Skip to content

Commit 0a96304

Browse files
committed
BUG: fix incorrect bin labels from cut when labels=False and NA present. close #1511
1 parent d8a0b4f commit 0a96304

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas/tools/tests/test_tile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def test_cut_corner(self):
6060

6161
self.assertRaises(ValueError, cut, [1, 2, 3], 0.5)
6262

63+
def test_cut_out_of_range_more(self):
64+
# #1511
65+
s = Series([0, -1, 0, 1, -3])
66+
ind = cut(s, [0, 1], labels=False)
67+
exp = [np.nan, np.nan, np.nan, 0, np.nan]
68+
assert_almost_equal(ind, exp)
6369

6470
def test_labels(self):
6571
arr = np.tile(np.arange(0, 1.01, 0.1), 4)

pandas/tools/tile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _bins_to_cuts(x, bins, right=True, labels=None, retbins=False,
180180
else:
181181
fac = ids - 1
182182
if has_nas:
183-
fac = ids.astype(np.float64)
183+
fac = fac.astype(np.float64)
184184
np.putmask(fac, na_mask, np.nan)
185185

186186
if not retbins:

0 commit comments

Comments
 (0)