{"record":{"id":"7162c81747fb075c","repo":"mlflow/mlflow","slug":"can-t-merge-array-with-non-array-type-type-other","errorCode":null,"errorMessage":"Can't merge array with non-array type: {type(other).__name__}","messagePattern":"Can't merge array with non-array type: (.+?)","errorType":"validation","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/types/schema.py","lineNumber":554,"sourceCode":"        elif kwargs[\"items\"][\"type\"] == SPARKML_VECTOR_TYPE:\n            item_type = SparkMLVector()\n        elif kwargs[\"items\"][\"type\"] == MAP_TYPE:\n            item_type = Map.from_json_dict(**kwargs[\"items\"])\n        elif kwargs[\"items\"][\"type\"] == ANY_TYPE:\n            item_type = AnyType()\n        else:\n            item_type = kwargs[\"items\"][\"type\"]\n\n        return cls(dtype=item_type)\n\n    def __repr__(self) -> str:\n        return f\"Array({self.dtype!r})\"\n\n    def _merge(self, other: BaseType) -> Array:\n        if isinstance(other, AnyType) or self == other:\n            return deepcopy(self)\n        if not isinstance(other, Array):\n            raise MlflowException(f\"Can't merge array with non-array type: {type(other).__name__}\")\n        if isinstance(self.dtype, DataType):\n            if self.dtype == other.dtype:\n                return Array(dtype=self.dtype)\n            raise MlflowException(\n                f\"Array types are incompatible for {self} with dtype={self.dtype} and \"\n                f\"{other} with dtype={other.dtype}\"\n            )\n\n        if isinstance(self.dtype, (Array, Object, Map, AnyType)):\n            return Array(dtype=self.dtype._merge(other.dtype))\n\n        raise MlflowException(f\"Array type {self!r} and {other!r} are incompatible\")\n\n\nclass SparkMLVector(Array):\n    \"\"\"\n    Specification used to represent a vector type in Spark ML.\n    \"\"\"","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/types/schema.py#L536-L572","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nArray(dtype=DataType.double)._merge(DataType.string)  # raises\n// after\nArray(dtype=DataType.double)._merge(Array(dtype=DataType.string))  # OK","handlingStrategy":"type-guard","validationCode":"def can_merge_arrays(a, b):\n    return isinstance(b, Array)\n\n# before merging schemas\ncol_a = schema_a.input_columns_dict()[name]\ncol_b = schema_b.input_columns_dict()[name]\nassert can_merge_arrays(col_a.type, col_b.type), f\"column {name} types differ\"","typeGuard":"def is_array_type(t) -> bool:\n    from mlflow.types.schema import Array\n    return isinstance(t, Array)","tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    merged = arr_type._merge(other)\nexcept MlflowException as e:\n    if \"Can't merge array with non-array\" in str(e):\n        merged = AnyType()._merge(other)  # or fix the input data\n    else:\n        raise","preventionTips":["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."],"tags":["schema","merge","typing","signature"],"backgroundTag":"schema-type-mismatch","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}