code: def _get_dummies_1d(
      data,
      prefix,
      prefix_sep="_",
      dummy_na=False,
      sparse=False,
      drop_first=False,
      dtype=None,
  ):
      from pandas.core.reshape.concat import concat
  
      # Series avoids inconsistent NaN handling
      codes, levels = _factorize_from_iterable(Series(data))
  
      if dtype is None:
          dtype = np.uint8
      dtype = np.dtype(dtype)
  
      if is_object_dtype(dtype):
          raise ValueError(
              "dtype=object is not a valid dtype for get_dummies"
          )
  
      def get_empty_frame(data):
          if isinstance(data, Series):
              index = data.index
          else:
              index = np.arange(len(data))
          return DataFrame(index=index)
  
      # if all NaN
      if not dummy_na and len(levels) == 0:
          return get_empty_frame(data)
  
      codes = codes.copy()
      if dummy_na:
          codes[codes == -1] = len(levels)
          levels = np.append(levels, np.nan)
  
      # if dummy_na, we just fake a nan level. drop_first will drop it again
      if drop_first and len(levels) == 1:
          return get_empty_frame(data)
  
      number_of_cols = len(levels)
  
      if prefix is None:
          dummy_cols = levels
      else:
          # PY2 embedded unicode, gh-22084
          def _make_col_name(prefix, prefix_sep, level):
              fstr = "{prefix}{prefix_sep}{level}"
              if PY2 and (
                  isinstance(prefix, text_type)
                  or isinstance(prefix_sep, text_type)
                  or isinstance(level, text_type)
              ):
                  fstr = u(fstr)
              return fstr.format(
                  prefix=prefix, prefix_sep=prefix_sep, level=level
              )
  
          dummy_cols = [
              _make_col_name(prefix, prefix_sep, level)
              for level in levels
          ]
  
      if isinstance(data, Series):
          index = data.index
      else:
          index = None
  
      if sparse:
          if is_integer_dtype(dtype):
              fill_value = 0
          elif dtype == bool:
              fill_value = False
          else:
              fill_value = 0.0
  
          sparse_series = []
          N = len(data)
          sp_indices = [[] for _ in range(len(dummy_cols))]
          mask = codes != -1
          codes = codes[mask]
          n_idx = np.arange(N)[mask]
  
          for ndx, code in zip(n_idx, codes):
              sp_indices[code].append(ndx)
  
          if drop_first:
              # remove first categorical level to avoid perfect collinearity
              # GH12042
              sp_indices = sp_indices[1:]
              dummy_cols = dummy_cols[1:]
          for col, ixs in zip(dummy_cols, sp_indices):
              sarr = SparseArray(
                  np.ones(len(ixs), dtype=dtype),
                  sparse_index=IntIndex(N, ixs),
                  fill_value=fill_value,
                  dtype=dtype,
              )
              sparse_series.append(
                  Series(data=sarr, index=index, name=col)
              )
  
          out = concat(sparse_series, axis=1, copy=False)
          return out
  
      else:
          dummy_mat = np.eye(number_of_cols, dtype=dtype).take(
              codes, axis=0
          )
  
          if not dummy_na:
              # reset NaN GH4446
              dummy_mat[codes == -1] = 0
  
          if drop_first:
              # remove first GH12042
              dummy_mat = dummy_mat[:, 1:]
              dummy_cols = dummy_cols[1:]
          return DataFrame(dummy_mat, index=index, columns=dummy_cols)
  
imports: from functools import partial
  import itertools
  import numpy
  from pandas._libs import algos, reshape
  from pandas._libs.sparse import IntIndex
  from pandas.compat import PY2, range, text_type, u, zip
  from pandas.core.dtypes.cast import maybe_promote
  from pandas.core.dtypes.common import ensure_platform_int, is_bool_dtype, is_extension_array_dtype, is_integer_dtype, is_list_like, is_object_dtype, needs_i8_conversion
  from pandas.core.dtypes.missing import notna
  from pandas import compat
  import pandas.core.algorithms
  from pandas.core.arrays import SparseArray
  from pandas.core.arrays.categorical import _factorize_from_iterable
  from pandas.core.frame import DataFrame
  from pandas.core.index import Index, MultiIndex
  from pandas.core.internals.arrays import extract_array
  from pandas.core.series import Series
  from pandas.core.sorting import compress_group_index, decons_obs_group_ids, get_compressed_ids, get_group_index
label_desc: Use image node_id 9 for calling a global function with example usage: _get_dummies_1d(data, prefix, prefix_sep, dummy_na, sparse, drop_first, dtype) and returns: DataFrame, get_empty_frame, get_empty_frame, out, DataFrame, fstr