Skip to content

Commit

Permalink
CLN: create core/sorting.py
Browse files Browse the repository at this point in the history
just a small reorg to put sorting / grouping utilities into a separate
area

Author: Jeff Reback <jeff@reback.net>

Closes pandas-dev#15402 from jreback/sorting and squashes the following commits:

fdcf9a1 [Jeff Reback] change a couple of sorting.py functions to be non-private (public to pandas internals)
90ff22d [Jeff Reback] split up some value_counts groupby tests a bit
18ea902 [Jeff Reback] CLN: create core/sorting.py
92dcb07 [Jeff Reback] CLN: remove numpy_groupby as not used
  • Loading branch information
jreback committed Feb 14, 2017
1 parent ff0deec commit 5959fe1
Show file tree
Hide file tree
Showing 13 changed files with 802 additions and 821 deletions.
26 changes: 13 additions & 13 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3141,7 +3141,7 @@ def duplicated(self, subset=None, keep='first'):
-------
duplicated : Series
"""
from pandas.core.groupby import get_group_index
from pandas.core.sorting import get_group_index
from pandas.hashtable import duplicated_int64, _SIZE_HINT_LIMIT

def f(vals):
Expand Down Expand Up @@ -3179,7 +3179,7 @@ def sort_values(self, by, axis=0, ascending=True, inplace=False,
raise ValueError('Length of ascending (%d) != length of by (%d)' %
(len(ascending), len(by)))
if len(by) > 1:
from pandas.core.groupby import _lexsort_indexer
from pandas.core.sorting import lexsort_indexer

def trans(v):
if needs_i8_conversion(v):
Expand All @@ -3193,11 +3193,11 @@ def trans(v):
raise ValueError('Cannot sort by duplicate column %s' %
str(x))
keys.append(trans(k))
indexer = _lexsort_indexer(keys, orders=ascending,
na_position=na_position)
indexer = lexsort_indexer(keys, orders=ascending,
na_position=na_position)
indexer = _ensure_platform_int(indexer)
else:
from pandas.core.groupby import _nargsort
from pandas.core.sorting import nargsort

by = by[0]
k = self.xs(by, axis=other_axis).values
Expand All @@ -3214,8 +3214,8 @@ def trans(v):
if isinstance(ascending, (tuple, list)):
ascending = ascending[0]

indexer = _nargsort(k, kind=kind, ascending=ascending,
na_position=na_position)
indexer = nargsort(k, kind=kind, ascending=ascending,
na_position=na_position)

new_data = self._data.take(indexer,
axis=self._get_block_manager_axis(axis),
Expand Down Expand Up @@ -3300,17 +3300,17 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
sort_remaining=sort_remaining)

elif isinstance(labels, MultiIndex):
from pandas.core.groupby import _lexsort_indexer
from pandas.core.sorting import lexsort_indexer

# make sure that the axis is lexsorted to start
# if not we need to reconstruct to get the correct indexer
if not labels.is_lexsorted():
labels = MultiIndex.from_tuples(labels.values)

indexer = _lexsort_indexer(labels.labels, orders=ascending,
na_position=na_position)
indexer = lexsort_indexer(labels.labels, orders=ascending,
na_position=na_position)
else:
from pandas.core.groupby import _nargsort
from pandas.core.sorting import nargsort

# GH11080 - Check monotonic-ness before sort an index
# if monotonic (already sorted), return None or copy() according
Expand All @@ -3322,8 +3322,8 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
else:
return self.copy()

indexer = _nargsort(labels, kind=kind, ascending=ascending,
na_position=na_position)
indexer = nargsort(labels, kind=kind, ascending=ascending,
na_position=na_position)

new_data = self._data.take(indexer,
axis=self._get_block_manager_axis(axis),
Expand Down
Loading

0 comments on commit 5959fe1

Please sign in to comment.