code: def canonicalize_observed_time_series_with_mask(
      maybe_masked_observed_time_series,
  ):
      """Extract a Tensor with canonical shape and optional mask.
  
      Args:
        maybe_masked_observed_time_series: a `Tensor`-like object with shape
          `[..., num_timesteps]` or `[..., num_timesteps, 1]`, or a
          `tfp.sts.MaskedTimeSeries` containing such an object, or a Pandas
          Series or DataFrame instance with set frequency
          (i.e., `.index.freq is not None`).
      Returns:
        masked_time_series: a `tfp.sts.MaskedTimeSeries` namedtuple, in which
          the `observed_time_series` is converted to `Tensor` with canonical shape
          `[..., num_timesteps, 1]`, and `is_missing` is either `None` or a boolean
          `Tensor`.
      """
  
      with tf.name_scope("canonicalize_observed_time_series_with_mask"):
          is_missing_is_specified = hasattr(
              maybe_masked_observed_time_series, "is_missing"
          )
          if is_missing_is_specified:
              # Input is a MaskedTimeSeries.
              observed_time_series = (
                  maybe_masked_observed_time_series.time_series
              )
              is_missing = maybe_masked_observed_time_series.is_missing
          elif hasattr(
              maybe_masked_observed_time_series, "index"
          ) and hasattr(maybe_masked_observed_time_series, "to_numpy"):
              # Input is a Pandas Series or DataFrame.
              index = maybe_masked_observed_time_series.index
              if hasattr(index, "freq") and index.freq is None:
                  raise ValueError(
                      "Pandas DataFrame or Series has a DatetimeIndex with "
                      "no set frequency, but STS requires regularly spaced "
                      "observations. Consider using "
                      "`tfp.sts.regularize_series` to infer a frequency and "
                      "build a regularly spaced series (by marking "
                      "unobserved steps as missing observations)."
                  )
              # When a DataFrame has multiple columns representing a batch of series,
              # we want shape `[batch_size, num_steps]` rather than vice versa.
              observed_time_series = np.squeeze(
                  np.transpose(
                      maybe_masked_observed_time_series.to_numpy()
                  )
              )
          else:
              observed_time_series = maybe_masked_observed_time_series
  
          observed_time_series = tf.convert_to_tensor(
              value=observed_time_series, name="observed_time_series"
          )
          observed_time_series = _maybe_expand_trailing_dim(
              observed_time_series
          )
  
          # Treat `NaN` values as missing.
          if not is_missing_is_specified:
              is_missing = tf.math.is_nan(observed_time_series[..., 0])
          is_missing_static = tf.get_static_value(is_missing)
          if is_missing_static is not None and not np.any(
              is_missing_static
          ):
              is_missing = None
          if is_missing is not None:
              is_missing = tf.convert_to_tensor(
                  value=is_missing,
                  name="is_missing",
                  dtype_hint=tf.bool,
              )
  
          return missing_values_util.MaskedTimeSeries(
              observed_time_series, is_missing=is_missing
          )
  
imports: import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.distributions import mixture_same_family
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import mvn_linear_operator
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.sts.internal import missing_values_util
label_desc: Use image node_id 8 for calling a global function with example usage: canonicalize_observed_time_series_with_mask(maybe_masked_observed_time_series) and returns: missing_values_util