code: def index_set_names(index, names, level=None, inplace=False):
      """
      Set Index or MultiIndex name.
  
      Able to set new names partially and by level.
  
      Parameters
      ----------
      names : label or list of label
          Name(s) to set.
      level : int, label or list of int or label, optional
          If the index is a MultiIndex, level(s) to set (None for all
          levels). Otherwise level must be None.
      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.rename : Able to set new names without level.
  
      Examples
      --------
      >>> import mars.dataframe as md
      >>> idx = md.Index([1, 2, 3, 4])
      >>> idx.execute()
      Int64Index([1, 2, 3, 4], dtype='int64')
      >>> idx.set_names('quarter').execute()
      Int64Index([1, 2, 3, 4], dtype='int64', name='quarter')
  
      >>> idx = md.MultiIndex.from_product([['python', 'cobra'],
      ...                                   [2018, 2019]])
      >>> idx.execute()
      MultiIndex([('python', 2018),
                  ('python', 2019),
                  ( 'cobra', 2018),
                  ( 'cobra', 2019)],
                 )
      >>> idx.set_names(['kind', 'year'], inplace=True)
      >>> idx.execute()
      MultiIndex([('python', 2018),
                  ('python', 2019),
                  ( 'cobra', 2018),
                  ( 'cobra', 2019)],
                 names=['kind', 'year'])
      >>> idx.set_names('species', level=0).execute()
      MultiIndex([('python', 2018),
                  ('python', 2019),
                  ( 'cobra', 2018),
                  ( 'cobra', 2019)],
                 names=['species', 'year'])
      """
      op = DataFrameRename(
          index_mapper=names,
          level=level,
          output_types=get_output_types(index),
      )
      ret = op(index)
  
      if inplace:
          df_or_series = getattr(
              index, "_get_df_or_series", lambda: None
          )()
          if df_or_series is not None:
              from .rename_axis import rename_axis_with_level
  
              rename_axis_with_level(
                  df_or_series,
                  names,
                  axis=index._axis,
                  level=level,
                  inplace=True,
              )
              index.data = df_or_series.axes[index._axis].data
          else:
              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 5 for calling a global function with example usage: index_set_names(index, names, level, inplace) and returns: ret