Skip to content

Commit

Permalink
BUG: fix incorrect bin labels from cut when labels=False and NA prese…
Browse files Browse the repository at this point in the history
…nt. close #1511
  • Loading branch information
wesm committed Jun 28, 2012
1 parent d8a0b4f commit 0a96304
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pandas/tools/tests/test_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def test_cut_corner(self):

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

def test_cut_out_of_range_more(self):
# #1511
s = Series([0, -1, 0, 1, -3])
ind = cut(s, [0, 1], labels=False)
exp = [np.nan, np.nan, np.nan, 0, np.nan]
assert_almost_equal(ind, exp)

def test_labels(self):
arr = np.tile(np.arange(0, 1.01, 0.1), 4)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tools/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _bins_to_cuts(x, bins, right=True, labels=None, retbins=False,
else:
fac = ids - 1
if has_nas:
fac = ids.astype(np.float64)
fac = fac.astype(np.float64)
np.putmask(fac, na_mask, np.nan)

if not retbins:
Expand Down

0 comments on commit 0a96304

Please sign in to comment.