{"record":{"id":"ef1d6a9f039ce390","repo":"mlflow/mlflow","slug":"map-types-are-incompatible-for-self-with-value-t","errorCode":null,"errorMessage":"Map types are incompatible for {self} with value_type={self.value_type} and {other} with value_type={other.value_type}","messagePattern":"Map types are incompatible for (.+?) with value_type=(.+?) and (.+?) with value_type=(.+?)","errorType":"validation","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/types/schema.py","lineNumber":672,"sourceCode":"        if kwargs[\"values\"][\"type\"] == ARRAY_TYPE:\n            return cls(value_type=Array.from_json_dict(**kwargs[\"values\"]))\n        if kwargs[\"values\"][\"type\"] == SPARKML_VECTOR_TYPE:\n            return SparkMLVector()\n        if kwargs[\"values\"][\"type\"] == MAP_TYPE:\n            return cls(value_type=Map.from_json_dict(**kwargs[\"values\"]))\n        if kwargs[\"values\"][\"type\"] == ANY_TYPE:\n            return cls(value_type=AnyType())\n        return cls(value_type=kwargs[\"values\"][\"type\"])\n\n    def _merge(self, other: BaseType) -> Map:\n        if isinstance(other, AnyType) or self == other:\n            return deepcopy(self)\n        if not isinstance(other, Map):\n            raise MlflowException(f\"Can't merge map with non-map type: {type(other).__name__}\")\n        if isinstance(self.value_type, DataType):\n            if self.value_type == other.value_type:\n                return Map(value_type=self.value_type)\n            raise MlflowException(\n                f\"Map types are incompatible for {self} with value_type={self.value_type} and \"\n                f\"{other} with value_type={other.value_type}\"\n            )\n\n        if isinstance(self.value_type, (Array, Object, Map, AnyType)):\n            return Map(value_type=self.value_type._merge(other.value_type))\n\n        raise MlflowException(f\"Map type {self!r} and {other!r} are incompatible\")\n\n\nclass AnyType(BaseType):\n    def __init__(self):\n        \"\"\"\n        AnyType can store any json-serializable data including None values.\n        For example:\n\n        .. code-block::python\n","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/types/schema.py#L654-L690","documentation":"When both operands of Map._merge are Maps but the left map's value_type is a simple DataType, the value types must be exactly equal (e.g. both double). Otherwise MLflow cannot decide a common value type and raises this error listing both incompatible maps.","triggerScenarios":"Merging two Map columns whose value types differ, e.g. Map(value_type=DataType.double)._merge(Map(value_type=DataType.float)) or Map(string) vs Map(long), via Schema merging during signature unification or schema enforcement.","commonSituations":"Numeric drift between training and serving signatures (double vs float, long vs int); one team logged signatures with float32 pandas columns and another with float64; map<string, bool> vs map<string, string> after a feature change; comparing models served from different framework versions that infer different dtypes.","solutions":["Align the map value types exactly: cast the data (e.g. df['col'] = df['col'].astype('float64')) so both signatures use the same DataType.","Re-infer the signature on the final, consistently-typed data with infer_signature and re-log the model.","If either value type is genuinely flexible, change one side to AnyType() so the merge produces the concrete other type.","For composite value types (Array/Object/Map), ensure the nested types are also mergeable; nested mismatches surface from the inner _merge."],"exampleFix":"// before\nMap(value_type=DataType.double)._merge(Map(value_type=DataType.float))\n// raises: Map types are incompatible ...\n\n// after\nMap(value_type=DataType.double)._merge(Map(value_type=DataType.double))","handlingStrategy":"validation","validationCode":"from mlflow.types.schema import Map, DataType\n\ndef maps_have_matching_value_types(a: Map, b: Map) -> bool:\n    if isinstance(a.value_type, DataType) and isinstance(b.value_type, DataType):\n        return a.value_type == b.value_type\n    return True","typeGuard":"def same_map_value_type(a: Map, b: Map) -> bool:\n    return isinstance(a.value_type, DataType) and a.value_type == b.value_type","tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    merged = map_a._merge(map_b)\nexcept MlflowException as e:\n    if \"Map types are incompatible\" in str(e):\n        cast_data_to_common_dtype()  # e.g. astype('float64') then re-infer signature\n    else:\n        raise","preventionTips":["Pin dataframe dtypes (float64, int64) before infer_signature so value types match across environments","Never mix float32/float64 or int/long representations for the same feature across model versions","Add a CI check that merges the new signature with the previously logged one"],"tags":["mlflow","schema","type-mismatch","merge","signature"],"backgroundTag":"schema-type-mismatch","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}