{"record":{"id":"658d1f201b047691","repo":"mlflow/mlflow","slug":"array-types-are-incompatible-for-self-with-dtype","errorCode":null,"errorMessage":"Array types are incompatible for {self} with dtype={self.dtype} and {other} with dtype={other.dtype}","messagePattern":"Array types are incompatible for (.+?) with dtype=(.+?) and (.+?) with dtype=(.+?)","errorType":"validation","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/types/schema.py","lineNumber":558,"sourceCode":"        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    \"\"\"\n\n    def __init__(self):\n        super().__init__(dtype=DataType.double)\n","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/types/schema.py#L540-L576","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nArray(dtype=DataType.double)._merge(Array(dtype=DataType.long))  # raises\n// after\ndf['col'] = df['col'].apply(lambda xs: [float(x) for x in xs])\nArray(dtype=DataType.double)._merge(Array(dtype=DataType.double))  # OK","handlingStrategy":"validation","validationCode":"from mlflow.types.schema import Array, DataType\n\ndef mergeable(a: Array, b: Array) -> bool:\n    return not (isinstance(a.dtype, DataType) and isinstance(b.dtype, DataType) and a.dtype != b.dtype)","typeGuard":"def same_scalar_dtype(a: Array, b: Array) -> bool:\n    from mlflow.types.schema import DataType\n    return not isinstance(a.dtype, DataType) or not isinstance(b.dtype, DataType) or a.dtype == b.dtype","tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    merged = arr_type._merge(other)\nexcept MlflowException as e:\n    if \"Array types are incompatible\" in str(e):\n        # cast data so element dtypes match, then retry\n        merged = Array(dtype=DataType.double)._merge(Array(dtype=DataType.double))\n    else:\n        raise","preventionTips":["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."],"tags":["schema","merge","dtype","signature"],"backgroundTag":"schema-type-mismatch","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}