<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sort_values(self, inplace=False, ascending=True, na_position='last'):
 """ Sort the Categorical by category value returning a new Categorical by default. While an ordering is applied to the category values, sorting in this context refers more to organizing and grouping together based on matching category values. Thus, this function can be called on an unordered Categorical instance unlike the functions 'Categorical.min' and 'Categorical.max'. Parameters inplace : bool, default False Do operation in place. ascending : bool, default True Order ascending. Passing False orders descending. The ordering parameter provides the method by which the category values are organized. na_position : {'first', 'last'} (optional, default='last') 'first' puts NaNs at the beginning 'last' puts NaNs at the end Returns ------- Categorical or None See Also -------- Categorical.sort Series.sort_values Examples -------- [1, 2, 2, 1, 5] Categories (3, int64):
 [1, 2, 5] [1, 1, 2, 2, 5] Categories (3, int64):
 [1, 2, 5] [5, 2, 2, 1, 1] Categories (3, int64):
 [1, 2, 5] Inplace sorting can be done as well: [1, 1, 2, 2, 5] Categories (3, int64):
 [1, 2, 5] 'sort_values' behaviour with NaNs. Note that 'na_position' is independent of the 'ascending' parameter: [NaN, 2.0, 2.0, NaN, 5.0] Categories (2, int64):
 [2, 5] [2.0, 2.0, 5.0, NaN, NaN] Categories (2, int64):
 [2, 5] [5.0, 2.0, 2.0, NaN, NaN] Categories (2, int64):
 [2, 5] [NaN, NaN, 2.0, 2.0, 5.0] Categories (2, int64):
 [2, 5] [NaN, NaN, 5.0, 2.0, 2.0] Categories (2, int64):
 [2, 5] """

        inplace = validate_bool_kwarg(inplace, 'inplace')
        if na_position not in ['last', 'first']:
            msg = 'invalid na_position: {na_position!r}'
            raise ValueError(msg.format(na_position=na_position))

        sorted_idx = nargsort(self,
                              ascending=ascending,
                              na_position=na_position)

        if inplace:
            self._codes = self._codes[sorted_idx]
        else:
            return self._constructor(values=self._codes[sorted_idx],
                                     dtype=self.dtype,
                                     fastpath=True)