class_docstr: Imputed Data
  
  This class should not be instantiated directly.
  Instead, it is returned when ImputationKernel.impute_new_data() is called.
  For parameter arguments, see ImputationKernel documentation.
class_docstr_tok: ["Imputed","Data","This","class","should","not","be","instantiated","directly",".","Instead",",","it","is","returned","when","ImputationKernel.impute_new_data","(",")","is","called",".","For","parameter","arguments",",","see","ImputationKernel","documentation","."]
code: def __init__(
      self,
      impute_data: _t_dat,
      datasets: int = 5,
      variable_schema: Union[_t_var_list, _t_var_dict, None] = None,
      imputation_order: Union[str, _t_var_list] = "ascending",
      train_nonmissing: bool = False,
      categorical_feature: Union[str, _t_var_list] = "auto",
      save_all_iterations: bool = True,
      copy_data: bool = True,
  ):
      # All references to the data should be through self.
      self.working_data = (
          impute_data.copy() if copy_data else impute_data
      )
      data_shape = self.working_data.shape
      int_storage_types = ["uint64", "uint32", "uint16", "uint8"]
      na_where_type = "uint64"
      for st in int_storage_types:
          if data_shape[0] <= np.iinfo(st).max:
              na_where_type = st
  
      # Collect metadata and format data
      if isinstance(self.working_data, pd_DataFrame):
          if (
              len(self.working_data.shape) != 2
              or self.working_data.shape[0] < 1
          ):
              raise ValueError(
                  "Input data must be 2 dimensional and non empty."
              )
  
          original_data_class = "pd_DataFrame"
          column_names: List[str] = [
              str(x) for x in self.working_data.columns
          ]
          self.column_names = column_names
          pd_dtypes_orig = self.working_data.dtypes
  
          if any([x.name == "object" for x in pd_dtypes_orig]):
              raise ValueError(
                  "Please convert object columns to categorical or some numeric type."
              )
  
          # Assume categories are set dtypes.
          if categorical_feature == "auto":
              categorical_variables = [
                  column_names.index(var)
                  for var in pd_dtypes_orig.index
                  if pd_dtypes_orig[var].name in ["category"]
              ]
  
          elif isinstance(categorical_feature, list):
              if any([x.name == "category" for x in pd_dtypes_orig]):
                  raise ValueError(
                      "If categories are already encoded as such, set categorical_feature = auto"
                  )
              categorical_variables = self._get_var_ind_from_list(
                  categorical_feature
              )
  
          else:
              raise ValueError("Unknown categorical_feature")
  
          # Collect category counts.
          category_counts = {}
          for cat in categorical_variables:
              cat_name = self._get_var_name_from_scalar(cat)
              cat_dat = self.working_data.iloc[:, cat]
              uniq = set(cat_dat.dropna())
              category_counts[cat] = len(uniq)
  
          # Collect info about what data is missing.
          na_where: Dict[int, np.ndarray] = {
              col: np.where(self.working_data.iloc[:, col].isnull())[
                  0
              ].astype(na_where_type)
              for col in range(data_shape[1])
          }
          na_counts = {col: len(nw) for col, nw in na_where.items()}
          vars_with_any_missing = [
              col for col, ind in na_where.items() if len(ind > 0)
          ]
          # if len(vars_with_any_missing) == 0:
          #     raise ValueError("No missing values to impute.")
  
          # Keep track of datatypes. Needed for loading kernels.
          self.working_dtypes = self.working_data.dtypes
  
      elif isinstance(self.working_data, np.ndarray):
          if (
              len(self.working_data.shape) != 2
              or self.working_data.shape[0] < 1
          ):
              raise ValueError(
                  "Input data must be 2 dimensional and non empty."
              )
  
          original_data_class = "np_ndarray"
  
          # DATASET ALTERATION
          if (
              self.working_data.dtype != np.float32
              and self.working_data.dtype != np.float64
          ):
              self.working_data = self.working_data.astype(np.float32)
  
          # Collect information about dataset
          column_names = [
              str(x) for x in range(self.working_data.shape[1])
          ]
          self.column_names = column_names
          na_where = {
              col: np.where(np.isnan(self.working_data[:, col]))[
                  0
              ].astype(na_where_type)
              for col in range(data_shape[1])
          }
          na_counts = {col: len(nw) for col, nw in na_where.items()}
          vars_with_any_missing = [
              int(col) for col, ind in na_where.items() if len(ind > 0)
          ]
          if categorical_feature == "auto":
              categorical_variables = []
          elif isinstance(categorical_feature, list):
              categorical_variables = self._get_var_ind_from_list(
                  categorical_feature
              )
              assert (
                  max(categorical_variables)
                  < self.working_data.shape[1]
              ), "categorical_feature not in dataset"
          else:
              raise ValueError("categorical_feature not recognized")
  
          # Collect category counts.
          category_counts = {}
          for cat in categorical_variables:
              cat_dat = self.working_data[:, cat]
              cat_dat = cat_dat[~np.isnan(cat_dat)]
              uniq = set(cat_dat)
              category_counts[cat] = len(uniq)
  
          # Keep track of datatype.
          self.working_dtypes = self.working_data.dtype
  
      else:
          raise ValueError("impute_data not recognized.")
  
      # Formatting of variable_schema.
      if variable_schema is None:
          variable_schema = _dict_set_diff(
              range(data_shape[1]), range(data_shape[1])
          )
      else:
          if isinstance(variable_schema, list):
              var_schem = self._get_var_ind_from_list(variable_schema)
              variable_schema = _dict_set_diff(
                  var_schem, range(data_shape[1])
              )
  
          elif isinstance(variable_schema, dict):
              variable_schema = self._get_var_ind_from_dict(
                  variable_schema
              )
  
              # Check for any self-impute attempts
              self_impute_attempt = [
                  var
                  for var, prd in variable_schema.items()
                  if var in prd
              ]
              if len(self_impute_attempt) > 0:
                  raise ValueError(
                      ",".join(
                          self._get_var_name_from_list(
                              self_impute_attempt
                          )
                      )
                      + " variables cannot be used to impute itself."
                  )
  
      # Format imputation order
      if isinstance(imputation_order, list):
          imputation_order = self._get_var_ind_from_list(
              imputation_order
          )
          assert set(imputation_order).issubset(
              variable_schema
          ), "variable_schema does not include all variables to be imputed."
          imputation_order = [
              i for i in imputation_order if na_counts[i] > 0
          ]
      elif isinstance(imputation_order, str):
          if imputation_order in ["ascending", "descending"]:
              imputation_order = self._get_var_ind_from_list(
                  np.argsort(list(na_counts.values())).tolist()
                  if imputation_order == "ascending"
                  else np.argsort(list(na_counts.values()))[
                      ::-1
                  ].tolist()
              )
              imputation_order = [
                  int(i)
                  for i in imputation_order
                  if na_counts[i] > 0 and i in list(variable_schema)
              ]
          elif imputation_order == "roman":
              imputation_order = list(variable_schema).copy()
          elif imputation_order == "arabic":
              imputation_order = list(variable_schema).copy()
              imputation_order.reverse()
          else:
              raise ValueError("imputation_order not recognized.")
  
      self.imputation_order = imputation_order
      self.variable_schema = variable_schema
      self.unimputed_variables = list(
          np.setdiff1d(np.arange(data_shape[1]), imputation_order)
      )
      if train_nonmissing:
          self.variable_training_order = [
              v
              for v in self.imputation_order + self.unimputed_variables
              if v in list(self.variable_schema)
          ]
      else:
          self.variable_training_order = self.imputation_order
      predictor_vars = [prd for prd in variable_schema.values()]
      self.predictor_vars = list(
          dict.fromkeys(
              [item for sublist in predictor_vars for item in sublist]
          )
      )
      self.categorical_feature = categorical_feature
      self.categorical_variables = categorical_variables
      self.category_counts = category_counts
      self.original_data_class = original_data_class
      self.save_all_iterations = save_all_iterations
      self.data_shape = data_shape
      self.na_counts = na_counts
      self.na_where = na_where
      self.vars_with_any_missing = vars_with_any_missing
      self.imputed_variable_count = len(imputation_order)
      self.modeled_variable_count = len(self.variable_training_order)
      self.iterations = np.zeros(
          shape=(datasets, self.modeled_variable_count)
      ).astype(int)
  
      # Create structure to store imputation values.
      # These will be initialized by an ImputationKernel.
      self.imputation_values: Dict[Any, np.ndarray] = {}
      self.initialized = False
  
imports: import numpy
  from .compat import pd_DataFrame
  from .utils import _t_dat, _t_var_list, _t_var_dict, _ensure_iterable, _dict_set_diff, _assign_col_values_without_copy, _slice, _subset_data
  from itertools import combinations
  from typing import Dict, List, Union, Any, Optional
  from warnings import warn
label_desc: Use image node_id 1 to create a new ImputedData object  with example: obj = ImputedData(impute_data, datasets, variable_schema, imputation_order, train_nonmissing, categorical_feature, save_all_iterations, copy_data)