nodes: 0, module; 1, function_definition; 2, function_name:sort_index; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, expression_statement; 14, comment:# TODO: this can be combined with DataFrame.sort_index impl as; 15, comment:# almost identical; 16, expression_statement; 17, comment:# Validate the axis parameter; 18, expression_statement; 19, expression_statement; 20, if_statement; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, expression_statement; 25, expression_statement; 26, if_statement; 27, identifier:axis; 28, integer:0; 29, identifier:level; 30, None; 31, identifier:ascending; 32, True; 33, identifier:inplace; 34, False; 35, identifier:kind; 36, string; 37, identifier:na_position; 38, string; 39, identifier:sort_remaining; 40, True; 41, comment:"""
          Sort Series by index labels.
  
          Returns a new Series sorted by label if `inplace` argument is
          ``False``, otherwise updates the original series and returns None.
  
          Parameters
          ----------
          axis : int, default 0
              Axis to direct sorting. This can only be 0 for Series.
          level : int, optional
              If not None, sort on values in specified index level(s).
          ascending : bool, default true
              Sort ascending vs. descending.
          inplace : bool, default False
              If True, perform operation in-place.
          kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort'
              Choice of sorting algorithm. See also :func:`numpy.sort` for more
              information.  'mergesort' is the only stable algorithm. For
              DataFrames, this option is only applied when sorting on a single
              column or label.
          na_position : {'first', 'last'}, default 'last'
              If 'first' puts NaNs at the beginning, 'last' puts NaNs at the end.
              Not implemented for MultiIndex.
          sort_remaining : bool, default True
              If True and sorting by level and index is multilevel, sort by other
              levels too (in order) after sorting by specified level.
  
          Returns
          -------
          Series
              The original Series sorted by the labels.
  
          See Also
          --------
          DataFrame.sort_index: Sort DataFrame by the index.
          DataFrame.sort_values: Sort DataFrame by the value.
          Series.sort_values : Sort Series by the value.
  
          Examples
          --------
          >>> s = pd.Series(['a', 'b', 'c', 'd'], index=[3, 2, 1, 4])
          >>> s.sort_index()
          1    c
          2    b
          3    a
          4    d
          dtype: object
  
          Sort Descending
  
          >>> s.sort_index(ascending=False)
          4    d
          3    a
          2    b
          1    c
          dtype: object
  
          Sort Inplace
  
          >>> s.sort_index(inplace=True)
          >>> s
          1    c
          2    b
          3    a
          4    d
          dtype: object
  
          By default NaNs are put at the end, but use `na_position` to place
          them at the beginning
  
          >>> s = pd.Series(['a', 'b', 'c', 'd'], index=[3, 2, 1, np.nan])
          >>> s.sort_index(na_position='first')
          NaN     d
           1.0    c
           2.0    b
           3.0    a
          dtype: object
  
          Specify index level to sort
  
          >>> arrays = [np.array(['qux', 'qux', 'foo', 'foo',
          ...                     'baz', 'baz', 'bar', 'bar']),
          ...           np.array(['two', 'one', 'two', 'one',
          ...                     'two', 'one', 'two', 'one'])]
          >>> s = pd.Series([1, 2, 3, 4, 5, 6, 7, 8], index=arrays)
          >>> s.sort_index(level=1)
          bar  one    8
          baz  one    6
          foo  one    4
          qux  one    2
          bar  two    7
          baz  two    5
          foo  two    3
          qux  two    1
          dtype: int64
  
          Does not sort by remaining levels when sorting by levels
  
          >>> s.sort_index(level=1, sort_remaining=False)
          qux  one    2
          foo  one    4
          baz  one    6
          bar  one    8
          qux  two    1
          foo  two    3
          baz  two    5
          bar  two    7
          dtype: int64
          """; 42, assignment; 43, call; 44, assignment; 45, comparison_operator:level is not None; 46, block; 47, elif_clause; 48, else_clause; 49, assignment; 50, assignment; 51, assignment; 52, assignment; 53, assignment; 54, identifier:inplace; 55, block; 56, else_clause; 57, string_content:quicksort; 58, string_content:last; 59, identifier:inplace; 60, call; 61, attribute; 62, argument_list; 63, identifier:index; 64, attribute; 65, identifier:level; 66, None; 67, expression_statement; 68, call; 69, block; 70, block; 71, identifier:indexer; 72, call; 73, identifier:new_index; 74, call; 75, identifier:new_index; 76, call; 77, identifier:new_values; 78, call; 79, identifier:result; 80, call; 81, expression_statement; 82, block; 83, identifier:validate_bool_kwarg; 84, argument_list; 85, identifier:self; 86, identifier:_get_axis_number; 87, identifier:axis; 88, identifier:self; 89, identifier:index; 90, assignment; 91, identifier:isinstance; 92, argument_list; 93, import_from_statement; 94, expression_statement; 95, expression_statement; 96, import_from_statement; 97, comment:# Check monotonic-ness before sort an index; 98, comment:# GH11080; 99, if_statement; 100, expression_statement; 101, identifier:ensure_platform_int; 102, argument_list; 103, attribute; 104, argument_list; 105, attribute; 106, argument_list; 107, attribute; 108, argument_list; 109, attribute; 110, argument_list; 111, call; 112, return_statement; 113, identifier:inplace; 114, string; 115, pattern_list; 116, call; 117, identifier:index; 118, identifier:MultiIndex; 119, dotted_name; 120, dotted_name; 121, assignment; 122, assignment; 123, dotted_name; 124, dotted_name; 125, parenthesized_expression; 126, block; 127, assignment; 128, identifier:indexer; 129, identifier:index; 130, identifier:take; 131, identifier:indexer; 132, identifier:new_index; 133, identifier:_sort_levels_monotonic; 134, attribute; 135, identifier:take; 136, identifier:indexer; 137, identifier:self; 138, identifier:_constructor; 139, identifier:new_values; 140, keyword_argument; 141, attribute; 142, argument_list; 143, call; 144, string_content:inplace; 145, identifier:new_index; 146, identifier:indexer; 147, attribute; 148, argument_list; 149, identifier:pandas; 150, identifier:core; 151, identifier:sorting; 152, identifier:lexsort_indexer; 153, identifier:labels; 154, call; 155, identifier:indexer; 156, call; 157, identifier:pandas; 158, identifier:core; 159, identifier:sorting; 160, identifier:nargsort; 161, boolean_operator; 162, if_statement; 163, identifier:indexer; 164, call; 165, identifier:self; 166, identifier:_values; 167, identifier:index; 168, identifier:new_index; 169, identifier:self; 170, identifier:_update_inplace; 171, identifier:result; 172, attribute; 173, argument_list; 174, identifier:index; 175, identifier:sortlevel; 176, identifier:level; 177, keyword_argument; 178, keyword_argument; 179, attribute; 180, argument_list; 181, identifier:lexsort_indexer; 182, argument_list; 183, parenthesized_expression; 184, parenthesized_expression; 185, identifier:inplace; 186, block; 187, else_clause; 188, identifier:nargsort; 189, argument_list; 190, identifier:result; 191, identifier:__finalize__; 192, identifier:self; 193, identifier:ascending; 194, identifier:ascending; 195, identifier:sort_remaining; 196, identifier:sort_remaining; 197, identifier:index; 198, identifier:_sort_levels_monotonic; 199, call; 200, keyword_argument; 201, keyword_argument; 202, boolean_operator; 203, boolean_operator; 204, return_statement; 205, block; 206, identifier:index; 207, keyword_argument; 208, keyword_argument; 209, keyword_argument; 210, attribute; 211, argument_list; 212, identifier:orders; 213, identifier:ascending; 214, identifier:na_position; 215, identifier:na_position; 216, identifier:ascending; 217, attribute; 218, not_operator; 219, attribute; 220, return_statement; 221, identifier:kind; 222, identifier:kind; 223, identifier:ascending; 224, identifier:ascending; 225, identifier:na_position; 226, identifier:na_position; 227, identifier:labels; 228, identifier:_get_codes_for_sorting; 229, identifier:index; 230, identifier:is_monotonic_increasing; 231, identifier:ascending; 232, identifier:index; 233, identifier:is_monotonic_decreasing; 234, call; 235, attribute; 236, argument_list; 237, identifier:self; 238, identifier:copy
code: def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
                     kind='quicksort', na_position='last', sort_remaining=True):
          """
          Sort Series by index labels.
  
          Returns a new Series sorted by label if `inplace` argument is
          ``False``, otherwise updates the original series and returns None.
  
          Parameters
          ----------
          axis : int, default 0
              Axis to direct sorting. This can only be 0 for Series.
          level : int, optional
              If not None, sort on values in specified index level(s).
          ascending : bool, default true
              Sort ascending vs. descending.
          inplace : bool, default False
              If True, perform operation in-place.
          kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort'
              Choice of sorting algorithm. See also :func:`numpy.sort` for more
              information.  'mergesort' is the only stable algorithm. For
              DataFrames, this option is only applied when sorting on a single
              column or label.
          na_position : {'first', 'last'}, default 'last'
              If 'first' puts NaNs at the beginning, 'last' puts NaNs at the end.
              Not implemented for MultiIndex.
          sort_remaining : bool, default True
              If True and sorting by level and index is multilevel, sort by other
              levels too (in order) after sorting by specified level.
  
          Returns
          -------
          Series
              The original Series sorted by the labels.
  
          See Also
          --------
          DataFrame.sort_index: Sort DataFrame by the index.
          DataFrame.sort_values: Sort DataFrame by the value.
          Series.sort_values : Sort Series by the value.
  
          Examples
          --------
          >>> s = pd.Series(['a', 'b', 'c', 'd'], index=[3, 2, 1, 4])
          >>> s.sort_index()
          1    c
          2    b
          3    a
          4    d
          dtype: object
  
          Sort Descending
  
          >>> s.sort_index(ascending=False)
          4    d
          3    a
          2    b
          1    c
          dtype: object
  
          Sort Inplace
  
          >>> s.sort_index(inplace=True)
          >>> s
          1    c
          2    b
          3    a
          4    d
          dtype: object
  
          By default NaNs are put at the end, but use `na_position` to place
          them at the beginning
  
          >>> s = pd.Series(['a', 'b', 'c', 'd'], index=[3, 2, 1, np.nan])
          >>> s.sort_index(na_position='first')
          NaN     d
           1.0    c
           2.0    b
           3.0    a
          dtype: object
  
          Specify index level to sort
  
          >>> arrays = [np.array(['qux', 'qux', 'foo', 'foo',
          ...                     'baz', 'baz', 'bar', 'bar']),
          ...           np.array(['two', 'one', 'two', 'one',
          ...                     'two', 'one', 'two', 'one'])]
          >>> s = pd.Series([1, 2, 3, 4, 5, 6, 7, 8], index=arrays)
          >>> s.sort_index(level=1)
          bar  one    8
          baz  one    6
          foo  one    4
          qux  one    2
          bar  two    7
          baz  two    5
          foo  two    3
          qux  two    1
          dtype: int64
  
          Does not sort by remaining levels when sorting by levels
  
          >>> s.sort_index(level=1, sort_remaining=False)
          qux  one    2
          foo  one    4
          baz  one    6
          bar  one    8
          qux  two    1
          foo  two    3
          baz  two    5
          bar  two    7
          dtype: int64
          """
          # TODO: this can be combined with DataFrame.sort_index impl as
          # almost identical
          inplace = validate_bool_kwarg(inplace, 'inplace')
          # Validate the axis parameter
          self._get_axis_number(axis)
          index = self.index
  
          if level is not None:
              new_index, indexer = index.sortlevel(level, ascending=ascending,
                                                   sort_remaining=sort_remaining)
          elif isinstance(index, MultiIndex):
              from pandas.core.sorting import lexsort_indexer
              labels = index._sort_levels_monotonic()
              indexer = lexsort_indexer(labels._get_codes_for_sorting(),
                                        orders=ascending,
                                        na_position=na_position)
          else:
              from pandas.core.sorting import nargsort
  
              # Check monotonic-ness before sort an index
              # GH11080
              if ((ascending and index.is_monotonic_increasing) or
                      (not ascending and index.is_monotonic_decreasing)):
                  if inplace:
                      return
                  else:
                      return self.copy()
  
              indexer = nargsort(index, kind=kind, ascending=ascending,
                                 na_position=na_position)
  
          indexer = ensure_platform_int(indexer)
          new_index = index.take(indexer)
          new_index = new_index._sort_levels_monotonic()
  
          new_values = self._values.take(indexer)
          result = self._constructor(new_values, index=new_index)
  
          if inplace:
              self._update_inplace(result)
          else:
              return result.__finalize__(self)