Skip to content

CLN: create core/sorting.py #15402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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