mlflow/mlflow · error · MlflowException

Failed to convert column {name} from type {values.dtype} to

Error message

Failed to convert column {name} from type {values.dtype} to {t}.

What it means

For object-dtype or python-datetime columns expected to be datetime, MLflow attempts values.astype(datetime64[ns], errors='raise'). If any element cannot be parsed into a datetime (e.g. malformed strings, mixed types), ValueError is raised and wrapped in this exception naming the column and both types. This is the column-level conversion path for PySpark date columns converted to object dtype.

Source

Thrown at mlflow/models/utils.py:808

    if t == DataType.datetime and values.dtype.kind == t.to_numpy().kind:
        # NB: datetime values have variable precision denoted by brackets, e.g. datetime64[ns]
        # denotes nanosecond precision. Since MLflow datetime type is precision agnostic, we
        # ignore precision when matching datetime columns.
        try:
            return values.astype(np.dtype("datetime64[ns]"))
        except TypeError as e:
            raise MlflowException(
                "Please ensure that the input data of datetime column only contains timezone-naive "
                f"datetime objects. Error: {e}"
            )

    if t == DataType.datetime and (values.dtype == object or values.dtype == t.to_python()):
        # NB: Pyspark date columns get converted to object when converted to a pandas
        # DataFrame. To respect the original typing, we convert the column to datetime.
        try:
            return values.astype(np.dtype("datetime64[ns]"), errors="raise")
        except ValueError as e:
            raise MlflowException(
                f"Failed to convert column {name} from type {values.dtype} to {t}."
            ) from e

    if t == DataType.boolean and values.dtype == object:
        # Should not convert type otherwise it converts None to boolean False
        return values

    if t == DataType.double and values.dtype == decimal.Decimal:
        # NB: Pyspark Decimal column get converted to decimal.Decimal when converted to pandas
        # DataFrame. In order to support decimal data training from spark data frame, we add this
        # conversion even we might lose the precision.
        try:
            return pd.to_numeric(values, errors="raise")
        except ValueError:
            raise MlflowException(
                f"Failed to convert column {name} from type {values.dtype} to {t}."
            )

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Pre-convert the column with pd.to_datetime(df[name], errors='coerce') and inspect/handle rows that became NaT
  2. Fix or drop rows with invalid date values before calling predict
  3. Parse strings with an explicit format: pd.to_datetime(df[name], format='%Y-%m-%d')
  4. If the column genuinely isn't datetime, correct the model signature or the incoming data type

Example fix

# before
df["date"] = df["date"].astype(str)  # mixed/unparsable strings
model.predict(df)

// after
df["date"] = pd.to_datetime(df["date"], format="%Y-%m-%d", errors="coerce")
df = df.dropna(subset=["date"])
model.predict(df)
Defensive patterns

Strategy: validation

Validate before calling

import pandas as pd
for col, t in schema.column_types().items():
    if str(t).endswith("datetime"):
        bad = pd.to_datetime(df[col], errors="coerce").isna() & df[col].notna()
        assert not bad.any(), f"unparsable datetime values in {col}: {df.loc[bad, col].head().tolist()}"

Type guard

def is_parsable_datetime(v) -> bool:
    return isinstance(v, (datetime.datetime, datetime.date, str)) and bool(str(v).strip()) and pd.notna(pd.to_datetime(v, errors="coerce"))

Try / catch

try:
    preds = model.predict(df)
except MlflowException as e:
    if "Failed to convert column" in str(e):
        col = str(e).split("column ")[1].split(" ")[0]
        df[col] = pd.to_datetime(df[col], errors="coerce")
        preds = model.predict(df.dropna(subset=[col]))
    else:
        raise

Prevention

When it happens

Trigger: Column declared datetime in the signature but data contains unparsable strings like 'not-a-date', mixed str/datetime objects, or None mixed into an object column being converted.

Common situations: Pyspark DataFrames converted to pandas where date columns become object dtype; CSV reads leaving mixed-type date columns; user input forms sending free-text dates.

Related errors


AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29). Data as JSON: /api/errors/72a66fc7ae644dab. Report an issue: GitHub.