class_docstr: Represents an input example for MLflow model.
  
  Contains jsonable data that can be saved with the model and meta data about the exported format
  that can be saved with :py:class:`Model <mlflow.models.Model>`.
  
  The _Example is created from example data provided by user. The example(s) can be provided as
  pandas.DataFrame, numpy.ndarray, python dictionary or python list. The assumption is that the
  example contains jsonable elements (see storage format section below).
  
  NOTE: If the example is 1 dimensional (e.g. dictionary of str -> scalar, or a list of scalars),
  the assumption is that it is a single column of data.
  
  Metadata:
  
  The _Example metadata contains the following information:
      - artifact_path: Relative path to the serialized example within the model directory.
      - type: Type of example data provided by the user. E.g. dataframe, ndarray.
      - One of the following metadata based on the `type`:
          - pandas_orient: For dataframes, this attribute specifies how is the dataframe encoded
                           in json. For example, "split" value signals that the data is stored as
                           object with columns and data attributes.
          - format: For tensors, this attribute specifies the standard being used to store an
                    input example. MLflow uses a JSON-formatted string representation of T
                    F serving input.
  
  Storage Format:
  
  The examples are stored as json for portability and readability. Therefore, the contents of the
  example(s) must be jsonable. MLflow will make the following conversions automatically on behalf
  of the user:
  
      - binary values: :py:class:`bytes` or :py:class:`bytearray` are converted to base64
        encoded strings.
      - numpy types: Numpy types are converted to the corresponding python types or their closest
        equivalent.
      - csc/csr matrix: similar to 2 dims numpy array, csc/csr matrix are converted to
        corresponding python types or their closest equivalent.
class_docstr_tok: ["Represents","an","input","example","for","MLflow","model",".","Contains","jsonable","data","that","can","be","saved","with","the","model","and","meta","data","about","the","exported","format","that","can","be","saved","with",":","py",":","class",":","`","Model","<","mlflow.models.Model",">","`",".","The","_Example","is","created","from","example","data","provided","by","user",".","The","example","(","s",")","can","be","provided","as","pandas.DataFrame",",","numpy.ndarray",",","python","dictionary","or","python","list",".","The","assumption","is","that","the","example","contains","jsonable","elements","(","see","storage","format","section","below",")",".","NOTE",":","If","the","example","is","1","dimensional","(","e.g",".","dictionary","of","str","-",">","scalar",",","or","a","list","of","scalars",")",",","the","assumption","is","that","it","is","a","single","column","of","data",".","Metadata",":","The","_Example","metadata","contains","the","following","information",":","-","artifact_path",":","Relative","path","to","the","serialized","example","within","the","model","directory",".","-","type",":","Type","of","example","data","provided","by","the","user",".","E.g",".","dataframe",",","ndarray",".","-","One","of","the","following","metadata","based","on","the","`","type","`",":","-","pandas_orient",":","For","dataframes",",","this","attribute","specifies","how","is","the","dataframe","encoded","in","json",".","For","example",",","``","split","''","value","signals","that","the","data","is","stored","as","object","with","columns","and","data","attributes",".","-","format",":","For","tensors",",","this","attribute","specifies","the","standard","being","used","to","store","an","input","example",".","MLflow","uses","a","JSON-formatted","string","representation","of","T","F","serving","input",".","Storage","Format",":","The","examples","are","stored","as","json","for","portability","and","readability",".","Therefore",",","the","contents","of","the","example","(","s",")","must","be","jsonable",".","MLflow","will","make","the","following","conversions","automatically","on","behalf","of","the","user",":","-","binary","values",":",":","py",":","class",":","`","bytes","`","or",":","py",":","class",":","`","bytearray","`","are","converted","to","base64","encoded","strings",".","-","numpy","types",":","Numpy","types","are","converted","to","the","corresponding","python","types","or","their","closest","equivalent",".","-","csc\/csr","matrix",":","similar","to","2","dims","numpy","array",",","csc\/csr","matrix","are","converted","to","corresponding","python","types","or","their","closest","equivalent","."]
code: def __init__(self, input_example: ModelInputExample):
      def _is_scalar(x):
          return np.isscalar(x) or x is None
  
      def _validate_params(params):
          try:
              _infer_param_schema(params)
          except MlflowException:
              _logger.warning(
                  f"Invalid params found in input example: {params}"
              )
              raise
  
      def _is_ndarray(x):
          return isinstance(x, np.ndarray) or (
              isinstance(x, dict)
              and all(isinstance(ary, np.ndarray) for ary in x.values())
          )
  
      def _is_sparse_matrix(x):
          if not HAS_SCIPY:
              # we can safely assume that if no scipy is installed,
              # the user won't log scipy sparse matrices
              return False
          return isinstance(x, (csc_matrix, csr_matrix))
  
      def _handle_ndarray_nans(x: np.ndarray):
          if np.issubdtype(x.dtype, np.number):
              return np.where(np.isnan(x), None, x)
          else:
              return x
  
      def _handle_ndarray_input(input_array: Union[np.ndarray, dict]):
          if isinstance(input_array, dict):
              result = {}
              for name in input_array.keys():
                  result[name] = _handle_ndarray_nans(
                      input_array[name]
                  ).tolist()
              return {"inputs": result}
          else:
              return {
                  "inputs": _handle_ndarray_nans(input_array).tolist()
              }
  
      def _handle_sparse_matrix(x: Union["csr_matrix", "csc_matrix"]):
          return {
              "data": _handle_ndarray_nans(x.data).tolist(),
              "indices": x.indices.tolist(),
              "indptr": x.indptr.tolist(),
              "shape": list(x.shape),
          }
  
      def _handle_dataframe_nans(df: pd.DataFrame):
          return df.where(df.notnull(), None)
  
      def _coerce_to_pandas_df(input_ex):
          if isinstance(input_ex, dict):
              # We need to be compatible with infer_schema's behavior, where
              # it infers each value's type directly.
              if all(
                  isinstance(x, str)
                  or (
                      isinstance(x, list)
                      and all(_is_scalar(y) for y in x)
                  )
                  for x in input_ex.values()
              ):
                  # e.g.
                  # data = {"a": "a", "b": ["a", "b", "c"]}
                  # >>> pd.DataFrame([data])
                  #    a          b
                  # 0  a  [a, b, c]
                  _logger.info(
                      "We convert input dictionaries to pandas DataFrames such that "
                      "each key represents a column, collectively constituting a "
                      "single row of data. If you would like to save data as "
                      "multiple rows, please convert your data to a pandas "
                      "DataFrame before passing to input_example."
                  )
              input_ex = pd.DataFrame([input_ex])
          elif np.isscalar(input_ex):
              input_ex = pd.DataFrame([input_ex])
          elif not isinstance(input_ex, pd.DataFrame):
              try:
                  import pyspark.sql.dataframe
  
                  if isinstance(
                      input_example, pyspark.sql.dataframe.DataFrame
                  ):
                      raise MlflowException(
                          "Examples can not be provided as Spark Dataframe. "
                          "Please make sure your example is of a small size and "
                          "turn it into a pandas DataFrame."
                      )
              except ImportError:
                  pass
              input_ex = None
          return input_ex
  
      def _handle_dataframe_input(df):
          result = _handle_dataframe_nans(df).to_dict(orient="split")
          # Do not include row index
          del result["index"]
          if all(df.columns == range(len(df.columns))):
              # No need to write default column index out
              del result["columns"]
          return result
  
      self.info = {
          INPUT_EXAMPLE_PATH: EXAMPLE_FILENAME,
      }
      # Avoid changing the variable passed in
      input_example = deepcopy(input_example)
      if _contains_params(input_example):
          input_example, self._inference_params = input_example
          _validate_params(self._inference_params)
          self.info[EXAMPLE_PARAMS_KEY] = "true"
      else:
          self._inference_params = None
  
      if _is_ndarray(input_example):
          self._inference_data = input_example
          self.data = _handle_ndarray_input(input_example)
          self.info.update(
              {
                  "type": "ndarray",
                  "format": "tf-serving",
              }
          )
      elif _is_sparse_matrix(input_example):
          self._inference_data = input_example
          self.data = _handle_sparse_matrix(input_example)
          if isinstance(input_example, csc_matrix):
              example_type = "sparse_matrix_csc"
          else:
              example_type = "sparse_matrix_csr"
          self.info.update(
              {
                  "type": example_type,
              }
          )
      elif isinstance(input_example, list):
          for i, x in enumerate(input_example):
              if isinstance(x, np.ndarray) and len(x.shape) > 1:
                  raise TensorsNotSupportedException(
                      f"Row '{i}' has shape {x.shape}"
                  )
          if all(_is_scalar(x) for x in input_example):
              # We should not convert data for langchain flavors
              # List[scalar] is a typical langchain model input type
              _logger.info(
                  "Lists of scalar values are not converted to a pandas DataFrame. "
                  "If you expect to use pandas DataFrames for inference, please "
                  "construct a DataFrame and pass it to input_example instead."
              )
              self._inference_data = input_example
              self.data = {"inputs": self._inference_data}
              self.info.update(
                  {
                      "type": "ndarray",
                      "format": "tf-serving",
                  }
              )
          else:
              self._inference_data = pd.DataFrame(input_example)
              self.data = _handle_dataframe_input(self._inference_data)
              self.info.update(
                  {
                      "type": "dataframe",
                      "pandas_orient": "split",
                  }
              )
      else:
          self._inference_data = _coerce_to_pandas_df(input_example)
          if self._inference_data is None:
              raise TypeError(
                  "Expected one of the following types:\n"
                  "- pandas.DataFrame\n"
                  "- numpy.ndarray\n"
                  "- dictionary of (name -> numpy.ndarray)\n"
                  "- scipy.sparse.csr_matrix\n"
                  "- scipy.sparse.csc_matrix\n"
                  "- dict\n"
                  "- list\n"
                  "- scalars\n"
                  f"but got '{type(input_example)}'",
              )
          self.data = _handle_dataframe_input(self._inference_data)
          orient = "split" if "columns" in self.data else "values"
          self.info.update(
              {
                  "type": "dataframe",
                  "pandas_orient": orient,
              }
          )
  
imports: import datetime
  import decimal
  import json
  import logging
  import os
  from copy import deepcopy
  from typing import Any, Dict, List, Optional, Union
  import numpy
  import pandas
  from mlflow.exceptions import INVALID_PARAMETER_VALUE, MlflowException
  from mlflow.models import Model
  from mlflow.store.artifact.utils.models import get_model_name_and_version
  from mlflow.types import DataType, ParamSchema, ParamSpec, Schema, TensorSpec
  from mlflow.types.schema import Array, Object, Property
  from mlflow.types.utils import TensorsNotSupportedException, _infer_param_schema, clean_tensor_type
  from mlflow.utils.annotations import experimental
  from mlflow.utils.proto_json_utils import NumpyEncoder, dataframe_from_parsed_json, parse_tf_serving_input
  from mlflow.utils.uri import get_databricks_profile_uri_from_artifact_uri
label_desc: Use image node_id 1 to create a new _Example object  with example: obj = _Example(input_example)