code: def init_dict(data, index, columns, dtype=None):
      """
      Segregate Series based on type and coerce into matrices.
      Needs to handle a lot of exceptional cases.
      """
      if columns is not None:
          from pandas.core.series import Series
  
          arrays = Series(data, index=columns, dtype=object)
          data_names = arrays.index
  
          missing = arrays.isnull()
          if index is None:
              # GH10856
              # raise ValueError if only scalars in dict
              index = extract_index(arrays[~missing])
          else:
              index = ensure_index(index)
  
          # no obvious "empty" int column
          if missing.any() and not is_integer_dtype(dtype):
              if dtype is None or np.issubdtype(dtype, np.flexible):
                  # GH#1783
                  nan_dtype = object
              else:
                  nan_dtype = dtype
              val = construct_1d_arraylike_from_scalar(
                  np.nan, len(index), nan_dtype
              )
              arrays.loc[missing] = [val] * missing.sum()
  
      else:
          for key in data:
              if (
                  isinstance(data[key], ABCDatetimeIndex)
                  and data[key].tz is not None
              ):
                  # GH#24096 need copy to be deep for datetime64tz case
                  # TODO: See if we can avoid these copies
                  data[key] = data[key].copy(deep=True)
  
          keys = com.dict_keys_to_ordered_list(data)
          columns = data_names = Index(keys)
          arrays = [data[k] for k in keys]
  
      return arrays_to_mgr(
          arrays, data_names, index, columns, dtype=dtype
      )
  
imports: from collections import OrderedDict
  import numpy
  import numpy.ma
  from pandas._libs import lib
  from pandas._libs.tslibs import IncompatibleFrequency
  import pandas.compat
  from pandas.compat import get_range_parameters, lmap, lrange, raise_with_traceback, range
  from pandas.core.dtypes.cast import construct_1d_arraylike_from_scalar, construct_1d_ndarray_preserving_na, construct_1d_object_array_from_listlike, infer_dtype_from_scalar, maybe_cast_to_datetime, maybe_cast_to_integer_array, maybe_castable, maybe_convert_platform, maybe_infer_to_datetimelike, maybe_upcast
  from pandas.core.dtypes.common import is_categorical_dtype, is_datetime64tz_dtype, is_dtype_equal, is_extension_array_dtype, is_extension_type, is_float_dtype, is_integer_dtype, is_iterator, is_list_like, is_object_dtype, pandas_dtype
  from pandas.core.dtypes.generic import ABCDataFrame, ABCDatetimeIndex, ABCIndexClass, ABCPandasArray, ABCPeriodIndex, ABCSeries, ABCTimedeltaIndex
  from pandas.core.dtypes.missing import isna
  from pandas.core import algorithms, common
  from pandas.core.arrays import Categorical, ExtensionArray, period_array
  from pandas.core.index import Index, _get_objs_combined_axis, _union_indexes, ensure_index
  from pandas.core.indexes import base
  from pandas.core.internals import create_block_manager_from_arrays, create_block_manager_from_blocks
  from pandas.core.internals.arrays import extract_array
label_desc: Use image node_id 4 for calling a global function with example usage: init_dict(data, index, columns, dtype) and returns: arrays_to_mgr