Skip to content

Commit

Permalink
Fixed reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Apr 25, 2018
1 parent 82cad8b commit d5470a0
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,22 @@ def isna(self):
"""
raise AbstractMethodError(self)

def _values_for_factorize(self):
# type: () -> Tuple[ndarray, Any]
"""Return an array and missing value suitable for factorization.
def _values_for_argsort(self):
# type: () -> ndarray
"""Return values for sorting.
Returns
-------
values : ndarray
An array suitable for factoraization. This should maintain order
and be a supported dtype (Float64, Int64, UInt64, String, Object).
By default, the extension array is cast to object dtype.
na_value : object
The value in `values` to consider missing. This will be treated
as NA in the factorization routines, so it will be coded as
`na_sentinal` and not included in `uniques`. By default,
``np.nan`` is used.
ndarray
The transformed values should maintain the ordering between values
within the array.
See Also
--------
ExtensionArray.argsort
"""
return self.astype(object), np.nan
# Note: this is used in `ExtensionArray.argsort`.
return np.array(self)

def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
"""
Expand Down Expand Up @@ -393,6 +392,24 @@ def unique(self):
uniques = unique(self.astype(object))
return self._from_sequence(uniques)

def _values_for_factorize(self):
# type: () -> Tuple[ndarray, Any]
"""Return an array and missing value suitable for factorization.
Returns
-------
values : ndarray
An array suitable for factoraization. This should maintain order
and be a supported dtype (Float64, Int64, UInt64, String, Object).
By default, the extension array is cast to object dtype.
na_value : object
The value in `values` to consider missing. This will be treated
as NA in the factorization routines, so it will be coded as
`na_sentinal` and not included in `uniques`. By default,
``np.nan`` is used.
"""
return self.astype(object), np.nan

def factorize(self, na_sentinel=-1):
# type: (int) -> Tuple[ndarray, ExtensionArray]
"""Encode the extension array as an enumerated type.
Expand Down Expand Up @@ -445,22 +462,6 @@ def factorize(self, na_sentinel=-1):
# ------------------------------------------------------------------------
# Indexing methods
# ------------------------------------------------------------------------
def _values_for_argsort(self):
# type: () -> ndarray
"""Return values for sorting.
Returns
-------
ndarray
The transformed values should maintain the ordering between values
within the array.
See Also
--------
ExtensionArray.argsort
"""
# Note: this is used in `ExtensionArray.argsort`.
return np.array(self)

def take(self, indexer, allow_fill=False, fill_value=None):
# type: (Sequence[int], bool, Optional[Any]) -> ExtensionArray
Expand Down

0 comments on commit d5470a0

Please sign in to comment.