mlflow/mlflow · error · MlflowException
Can't merge array with non-array type: {type(other).__name__
Error message
Can't merge array with non-array type: {type(other).__name__} What it means
BaseType._merge combines two column/element types when unifying schemas (e.g. across training and inference inputs, or multiple dataset batches). Arrays can only be merged with another Array type; merging an Array with a scalar (double, string, tensor, etc.) is rejected with this error.
Source
Thrown at mlflow/types/schema.py:554
elif kwargs["items"]["type"] == SPARKML_VECTOR_TYPE:
item_type = SparkMLVector()
elif kwargs["items"]["type"] == MAP_TYPE:
item_type = Map.from_json_dict(**kwargs["items"])
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.
"""View on GitHub (pinned to 6a27f2decc)
Solutions
- Make the merged types consistent: wrap both sides as Array (or unwrap both to scalars) so they have the same shape.
- Check the offending column in both inputs and fix the data so its type matches across batches.
- If a column should allow any type, use AnyType (DataType.any / AnyType()) which merges with everything.
- If you intentionally want divergent schemas, do not merge them — keep separate model signatures.
Example fix
// before Array(dtype=DataType.double)._merge(DataType.string) # raises // after Array(dtype=DataType.double)._merge(Array(dtype=DataType.string)) # OK
Defensive patterns
Strategy: type-guard
Validate before calling
def can_merge_arrays(a, b):
return isinstance(b, Array)
# before merging schemas
col_a = schema_a.input_columns_dict()[name]
col_b = schema_b.input_columns_dict()[name]
assert can_merge_arrays(col_a.type, col_b.type), f"column {name} types differ" Type guard
def is_array_type(t) -> bool:
from mlflow.types.schema import Array
return isinstance(t, Array) Try / catch
from mlflow.exceptions import MlflowException
try:
merged = arr_type._merge(other)
except MlflowException as e:
if "Can't merge array with non-array" in str(e):
merged = AnyType()._merge(other) # or fix the input data
else:
raise Prevention
- Ensure list-like columns stay list-like across all batches used for infer_signature.
- Profile input DataFrames (dtypes of each column) before signature inference.
- Avoid mixing scalar and array representations of the same column across model versions.
- Use AnyType for columns whose element type may legitimately vary.
When it happens
Trigger: Calling Array._merge(other) where other is not an Array instance — e.g. unifying a schema where one input has an array column and the other a scalar of the same name, or merging ColSpec/Schema types with mismatched nesting.
Common situations: Infer_signature on heterogeneous batches, pandas DataFrames where one column is list-like in one batch and scalar in another, Spark columns whose type changed between runs, concatenating schemas from different model versions.
Related errors
- Array types are incompatible for {self} with dtype={self.dty
- Map types are incompatible for {self} with value_type={self.
- INVALID_PARAMETER_VALUE
- Can't merge property with non-property type: {type(other).__
- Can't merge properties with different names
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/7162c81747fb075c.
Report an issue: GitHub.