Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
BUG: fix DataFrame.rank on integer data close #1589
  • Loading branch information
wesm committed Jul 11, 2012
1 parent 3b0f698 commit 772e39a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE.rst
Expand Up @@ -54,6 +54,7 @@ pandas 0.8.1
- Unordered index with duplicates doesn't yield scalar location for single
entry (#1586)
- Fix resampling of tz-aware time series with "anchored" freq (#1591)
- Fix DataFrame.rank error on integer data (#1589)

pandas 0.8.0
============
Expand Down
1 change: 1 addition & 0 deletions pandas/core/algorithms.py
Expand Up @@ -310,6 +310,7 @@ def group_position(*args):

_rank2d_functions = {
'float64' : lib.rank_2d_float64,
'int64' : lib.rank_2d_int64,
'generic' : lib.rank_2d_generic
}

Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_frame.py
Expand Up @@ -5893,6 +5893,17 @@ def test_rank(self):
assert_almost_equal(ranks0.values, exp0)
assert_almost_equal(ranks1.values, exp1)

# integers
df = DataFrame(np.random.randint(0, 5, size=40).reshape((10, 4)))

result = df.rank()
exp = df.astype(float).rank()
assert_frame_equal(result, exp)

result = df.rank(1)
exp = df.astype(float).rank(1)
assert_frame_equal(result, exp)

def test_rank2(self):
from datetime import datetime

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/test_series.py
Expand Up @@ -1893,6 +1893,12 @@ def test_rank(self):

assert_almost_equal(ranks, exp)

iseries = Series(np.arange(5).repeat(2))

iranks = iseries.rank()
exp = iseries.astype(float).rank()
assert_series_equal(iranks, exp)

def test_from_csv(self):
self.ts.to_csv('_foo')
ts = Series.from_csv('_foo')
Expand Down

0 comments on commit 772e39a

Please sign in to comment.