mlflow/mlflow · error · MlflowException
Array types are incompatible for {self} with dtype={self.dty
Error message
Array types are incompatible for {self} with dtype={self.dtype} and {other} with dtype={other.dtype} What it means
When merging two Array types whose dtype is a concrete DataType (a scalar element type), the dtypes must be identical. This error fires when two arrays of different scalar element types are merged, e.g. Array(double) with Array(long).
Source
Thrown at mlflow/types/schema.py:558
elif kwargs["items"]["type"] == ANY_TYPE:
item_type = AnyType()
else:
item_type = kwargs["items"]["type"]
return cls(dtype=item_type)
def __repr__(self) -> str:
return f"Array({self.dtype!r})"
def _merge(self, other: BaseType) -> Array:
if isinstance(other, AnyType) or self == other:
return deepcopy(self)
if not isinstance(other, Array):
raise MlflowException(f"Can't merge array with non-array type: {type(other).__name__}")
if isinstance(self.dtype, DataType):
if self.dtype == other.dtype:
return Array(dtype=self.dtype)
raise MlflowException(
f"Array types are incompatible for {self} with dtype={self.dtype} and "
f"{other} with dtype={other.dtype}"
)
if isinstance(self.dtype, (Array, Object, Map, AnyType)):
return Array(dtype=self.dtype._merge(other.dtype))
raise MlflowException(f"Array type {self!r} and {other!r} are incompatible")
class SparkMLVector(Array):
"""
Specification used to represent a vector type in Spark ML.
"""
def __init__(self):
super().__init__(dtype=DataType.double)
View on GitHub (pinned to 6a27f2decc)
Solutions
- Cast one array's elements so both sides share the same dtype (e.g. convert long lists to double before inference).
- Use infer_signature on a single, consistently typed DataFrame so the element type is unambiguous.
- If the column may legitimately hold any element type, declare it as Array(AnyType()) or DataType.any which merges with any other array.
- Align the two schemas manually (edit ColSpec/Schema) so array element dtypes match before merging.
Example fix
// before Array(dtype=DataType.double)._merge(Array(dtype=DataType.long)) # raises // after df['col'] = df['col'].apply(lambda xs: [float(x) for x in xs]) Array(dtype=DataType.double)._merge(Array(dtype=DataType.double)) # OK
Defensive patterns
Strategy: validation
Validate before calling
from mlflow.types.schema import Array, DataType
def mergeable(a: Array, b: Array) -> bool:
return not (isinstance(a.dtype, DataType) and isinstance(b.dtype, DataType) and a.dtype != b.dtype) Type guard
def same_scalar_dtype(a: Array, b: Array) -> bool:
from mlflow.types.schema import DataType
return not isinstance(a.dtype, DataType) or not isinstance(b.dtype, DataType) or a.dtype == b.dtype Try / catch
from mlflow.exceptions import MlflowException
try:
merged = arr_type._merge(other)
except MlflowException as e:
if "Array types are incompatible" in str(e):
# cast data so element dtypes match, then retry
merged = Array(dtype=DataType.double)._merge(Array(dtype=DataType.double))
else:
raise Prevention
- Normalize numeric list columns (e.g. all float) before infer_signature.
- Check dtypes of list elements in each pandas/Spark batch before merging schemas.
- Cast int arrays to float when mixing with float arrays is intended.
- Compare schemas of training and serving data in CI to catch element-type drift.
When it happens
Trigger: Calling Array._merge where self.dtype and other.dtype are both DataType but unequal — e.g. merging input schemas containing Array(double) and Array(long) for the same column, or infer_signature over batches where a list column holds mixed numeric types.
Common situations: Pandas columns with lists of ints in one DataFrame and floats in another; numpy int64 vs float32 element types across batches; schema drift between training and serving data; merging signatures of two model versions.
Related errors
- Can't merge array with non-array type: {type(other).__name__
- Map types are incompatible for {self} with value_type={self.
- Unknown type: {dtype!r}
- INVALID_PARAMETER_VALUE
- dtype of input {actual_type} does not match expected dtype {
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/658d1f201b047691.
Report an issue: GitHub.