Skip to content

Commit

Permalink
Merge pull request #1321 from pratapvardhan/pd
Browse files Browse the repository at this point in the history
Pandas: sort(columns=) is deprecated, use sort_values(by=)
  • Loading branch information
cpcloud committed Nov 27, 2015
2 parents dde5cdb + d17b304 commit 0b38a21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
9 changes: 8 additions & 1 deletion blaze/compute/pandas.py
Expand Up @@ -18,6 +18,7 @@

import fnmatch
import itertools
from distutils.version import LooseVersion

import numpy as np

Expand Down Expand Up @@ -459,9 +460,15 @@ def concat_nodup(a, b):
return pd.concat([a, b], axis=1)


pdsort = getattr(
pd.DataFrame,
'sort' if LooseVersion(pd.__version__) < '0.17.0' else 'sort_values'
)


@dispatch(Sort, DataFrame)
def compute_up(t, df, **kwargs):
return df.sort(t.key, ascending=t.ascending)
return pdsort(df, t.key, ascending=t.ascending)


@dispatch(Sort, Series)
Expand Down
15 changes: 8 additions & 7 deletions blaze/compute/tests/test_pandas_compute.py
Expand Up @@ -13,6 +13,7 @@
from string import ascii_lowercase

from blaze.compute.core import compute
from blaze.compute.pandas import pdsort
from blaze import dshape, discover, transform
from blaze.expr import symbol, join, by, summary, distinct, shape
from blaze.expr import (merge, exp, mean, count, nunique, sum, min, max, any,
Expand Down Expand Up @@ -329,13 +330,13 @@ def test_join_promotion():

def test_sort():
tm.assert_frame_equal(compute(t.sort('amount'), df),
df.sort('amount'))
pdsort(df, 'amount'))

tm.assert_frame_equal(compute(t.sort('amount', ascending=True), df),
df.sort('amount', ascending=True))
pdsort(df, 'amount', ascending=True))

tm.assert_frame_equal(compute(t.sort(['amount', 'id']), df),
df.sort(['amount', 'id']))
pdsort(df, ['amount', 'id']))


def test_sort_on_series_no_warning(recwarn):
Expand Down Expand Up @@ -484,8 +485,8 @@ def test_outer_join():
(4., 'Dennis', 400., 'Moscow')],
columns=['id', 'name', 'amount', 'city'])

result = df.sort('id').to_records(index=False)
expected = expected.sort('id').to_records(index=False)
result = pdsort(df, 'id').to_records(index=False)
expected = pdsort(expected, 'id').to_records(index=False)
np.array_equal(result, expected)

df = compute(join(lsym, rsym, how='outer'), {lsym: left, rsym: right})
Expand All @@ -496,8 +497,8 @@ def test_outer_join():
(4., 'Dennis', 400., 'Moscow')],
columns=['id', 'name', 'amount', 'city'])

result = df.sort('id').to_records(index=False)
expected = expected.sort('id').to_records(index=False)
result = pdsort(df, 'id').to_records(index=False)
expected = pdsort(expected, 'id').to_records(index=False)
np.array_equal(result, expected)


Expand Down

0 comments on commit 0b38a21

Please sign in to comment.