code: def _get_level(x, nlevels, level_names):
      """Get the level index from a level number or name.
  
      If given an integer, this function will handle wraparound for
      negative values. If given a string (the level name), this function
      will extract the index of that level from `level_names`.
  
      Parameters
      ----------
      x
          The level number to validate
      nlevels
          The total available levels in the MultiIndex
      level_names
          The names of the levels.
      """
      if isinstance(x, int):
          if x < 0:
              x += nlevels
          if x >= nlevels:
              raise IndexError(
                  f"Level {x} out of bounds. Index has {nlevels} levels."
              )
          return x
      else:
          x = level_names.index(x)
          return x
  
imports: from __future__ import annotations
  import itertools
  import warnings
  from collections import abc
  from functools import cached_property, reduce
  from typing import TYPE_CHECKING, Any, Callable, Dict, Mapping, Optional, Tuple, Union
  import numpy
  import pandas
  from packaging.version import Version
  from pandas.api.types import is_bool
  from typing_extensions import Self
  import cudf
  from cudf.core import column
label_desc: Use image node_id 5 for calling a global function with example usage: _get_level(x, nlevels, level_names) and returns: x, x