code: def index_rename(index, name, inplace=False):
      """
      Alter Index or MultiIndex name.
  
      Able to set new names without level. Defaults to returning new index.
      Length of names must match number of levels in MultiIndex.
  
      Parameters
      ----------
      name : label or list of labels
          Name(s) to set.
      inplace : bool, default False
          Modifies the object directly, instead of creating a new Index or
          MultiIndex.
  
      Returns
      -------
      Index
          The same type as the caller or None if inplace is True.
  
      See Also
      --------
      Index.set_names : Able to set new names partially and by level.
  
      Examples
      --------
      >>> import mars.dataframe as md
      >>> idx = md.Index(['A', 'C', 'A', 'B'], name='score')
      >>> idx.rename('grade').execute()
      Index(['A', 'C', 'A', 'B'], dtype='object', name='grade')
  
      >>> idx = md.Index([('python', 2018),
      ...                 ('python', 2019),
      ...                 ('cobra', 2018),
      ...                 ('cobra', 2019)],
      ...                names=['kind', 'year'])
      >>> idx.execute()
      MultiIndex([('python', 2018),
                  ('python', 2019),
                  ( 'cobra', 2018),
                  ( 'cobra', 2019)],
                 names=['kind', 'year'])
      >>> idx.rename(['species', 'year']).execute()
      MultiIndex([('python', 2018),
                  ('python', 2019),
                  ( 'cobra', 2018),
                  ( 'cobra', 2019)],
                 names=['species', 'year'])
      >>> idx.rename('species').execute()
      Traceback (most recent call last):
      TypeError: Must pass list-like as `names`.
      """
      op = DataFrameRename(
          index_mapper=name, output_types=get_output_types(index)
      )
      ret = op(index)
      if inplace:
          index.data = ret.data
      else:
          return ret
  
imports: import warnings
  from ...None import opcodes
  from ...core import get_output_types, OutputType
  from ...serialization.serializables import AnyField, StringField
  from ..core import SERIES_TYPE
  from ..operands import DataFrameOperand, DataFrameOperandMixin
  from ..utils import build_df, build_series, validate_axis, parse_index
label_desc: Use image node_id 4 for calling a global function with example usage: index_rename(index, name, inplace) and returns: ret