def canonicalize_observed_time_series_with_mask(<EOL>maybe_masked_observed_time_series):
with tf.compat.v1.name_scope('<STR_LIT>'):<EOL><INDENT>if hasattr(maybe_masked_observed_time_series, '<STR_LIT>'):<EOL><INDENT>observed_time_series = (<EOL>maybe_masked_observed_time_series.time_series)<EOL>is_missing = maybe_masked_observed_time_series.is_missing<EOL><DEDENT>else:<EOL><INDENT>observed_time_series = maybe_masked_observed_time_series<EOL>is_missing = None<EOL><DEDENT>observed_time_series = tf.convert_to_tensor(value=observed_time_series,<EOL>name='<STR_LIT>')<EOL>observed_time_series = _maybe_expand_trailing_dim(observed_time_series)<EOL>if is_missing is not None:<EOL><INDENT>is_missing = tf.convert_to_tensor(<EOL>value=is_missing, name='<STR_LIT>', dtype_hint=tf.bool)<EOL><DEDENT>return missing_values_util.MaskedTimeSeries(observed_time_series,<EOL>is_missing=is_missing)<EOL><DEDENT>
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.
    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`.