Skip to content

Commit 5959fe1

Browse files
committed
CLN: create core/sorting.py
just a small reorg to put sorting / grouping utilities into a separate area Author: Jeff Reback <[email protected]> Closes #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
1 parent ff0deec commit 5959fe1

13 files changed

+802
-821
lines changed

pandas/core/frame.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -3141,7 +3141,7 @@ def duplicated(self, subset=None, keep='first'):
31413141
-------
31423142
duplicated : Series
31433143
"""
3144-
from pandas.core.groupby import get_group_index
3144+
from pandas.core.sorting import get_group_index
31453145
from pandas.hashtable import duplicated_int64, _SIZE_HINT_LIMIT
31463146

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

31843184
def trans(v):
31853185
if needs_i8_conversion(v):
@@ -3193,11 +3193,11 @@ def trans(v):
31933193
raise ValueError('Cannot sort by duplicate column %s' %
31943194
str(x))
31953195
keys.append(trans(k))
3196-
indexer = _lexsort_indexer(keys, orders=ascending,
3197-
na_position=na_position)
3196+
indexer = lexsort_indexer(keys, orders=ascending,
3197+
na_position=na_position)
31983198
indexer = _ensure_platform_int(indexer)
31993199
else:
3200-
from pandas.core.groupby import _nargsort
3200+
from pandas.core.sorting import nargsort
32013201

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

3217-
indexer = _nargsort(k, kind=kind, ascending=ascending,
3218-
na_position=na_position)
3217+
indexer = nargsort(k, kind=kind, ascending=ascending,
3218+
na_position=na_position)
32193219

32203220
new_data = self._data.take(indexer,
32213221
axis=self._get_block_manager_axis(axis),
@@ -3300,17 +3300,17 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
33003300
sort_remaining=sort_remaining)
33013301

33023302
elif isinstance(labels, MultiIndex):
3303-
from pandas.core.groupby import _lexsort_indexer
3303+
from pandas.core.sorting import lexsort_indexer
33043304

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

3310-
indexer = _lexsort_indexer(labels.labels, orders=ascending,
3311-
na_position=na_position)
3310+
indexer = lexsort_indexer(labels.labels, orders=ascending,
3311+
na_position=na_position)
33123312
else:
3313-
from pandas.core.groupby import _nargsort
3313+
from pandas.core.sorting import nargsort
33143314

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

3325-
indexer = _nargsort(labels, kind=kind, ascending=ascending,
3326-
na_position=na_position)
3325+
indexer = nargsort(labels, kind=kind, ascending=ascending,
3326+
na_position=na_position)
33273327

33283328
new_data = self._data.take(indexer,
33293329
axis=self._get_block_manager_axis(axis),

0 commit comments

Comments
 (0)