{"record":{"id":"980942662dc06a33","repo":"dotnet/machinelearning","slug":"string-format-strings-mismatchedcolumnvaluetype-t","errorCode":null,"errorMessage":"String.Format(Strings.MismatchedColumnValueType, this.DataType)","messagePattern":"String\\.Format\\(Strings\\.MismatchedColumnValueType, this\\.DataType\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameColumn.cs","lineNumber":275,"sourceCode":"        /// <summary>\n        /// Get occurences of each value from this column in other column, grouped by this value\n        /// </summary>\n        /// <param name=\"other\"></param>\n        /// <param name=\"otherColumnNullIndices\"></param>\n        /// <returns>A mapping of index from this column to the indices of same value in other column</returns>\n        public abstract Dictionary<long, ICollection<long>> GetGroupedOccurrences(DataFrameColumn other, out HashSet<long> otherColumnNullIndices);\n\n        /// <summary>\n        /// Get occurences of each value from this column in other column, grouped by this value\n        /// </summary>\n        /// <typeparam name=\"TKey\"></typeparam>\n        /// <param name=\"other\"></param>\n        /// <param name=\"otherColumnNullIndices\"></param>\n        /// <returns>A mapping of index from this column to the indices of same value in other column</returns>\n        protected Dictionary<long, ICollection<long>> GetGroupedOccurrences<TKey>(DataFrameColumn other, out HashSet<long> otherColumnNullIndices)\n        {\n            if (this.DataType != other.DataType)\n                throw new ArgumentException(String.Format(Strings.MismatchedColumnValueType, this.DataType), nameof(other));\n\n            // First hash other column   \n            Dictionary<TKey, ICollection<long>> multimap = other.GroupColumnValues<TKey>(out otherColumnNullIndices);\n\n            var ret = new Dictionary<long, ICollection<long>>();\n\n            //For each value in this column find rows from other column with equal value\n            for (int i = 0; i < this.Length; i++)\n            {\n                var value = this[i];\n                if (value != null && multimap.TryGetValue((TKey)value, out ICollection<long> otherRowIndices))\n                {\n                    ret.Add(i, otherRowIndices);\n                }\n            }\n\n            return ret;\n        }","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameColumn.cs#L257-L293","documentation":"GetGroupedOccurrences computes how row indices of `this` column map to indices of equal values in an `other` column, by hashing `other` with GroupColumnValues<TKey>. The operation is only defined when both columns hold the same element type, so it validates DataType equality up front and throws ArgumentException naming the `other` parameter. This mirrors how binary column operations elsewhere in Microsoft.Data.Analysis require compatible types.","triggerScenarios":"Calling a public API that internally calls GetGroupedOccurrences (e.g. column comparison/alignment operations used by DataFrame joins and binary operations) with two columns whose DataType differ, such as PrimitiveDataFrameColumn<int> vs PrimitiveDataFrameColumn<double> or a string column vs a numeric column.","commonSituations":"Joining or comparing DataFrames read from different sources where one parsed a column as int and the other as long/double; mixing a StringDataFrameColumn with a PrimitiveDataFrameColumn<T>; schema drift after a CSV schema inference change.","solutions":["Ensure both columns have the same DataType before the operation (compare column.DataType).","Explicitly cast/convert one column to the other's type (e.g. create a new PrimitiveDataFrameColumn<T> of the target type and populate it, or re-read the data with a consistent schema).","When loading data, pass explicit read options/schema so the same logical column is typed identically in both DataFrames."],"exampleFix":"// before\ndf1.Merge<int>(df2, leftKey, rightKey); // int vs double columns -> ArgumentException\n// after\nvar leftCol = (PrimitiveDataFrameColumn<int>)df1.Columns[leftKey];\nvar rightColDouble = (PrimitiveDataFrameColumn<double>)df2.Columns[rightKey];\nvar rightCol = rightColDouble.Select(v => (int)v).ToColumn(rightKey); // match types first","handlingStrategy":"validation","validationCode":"if (leftCol.DataType != rightCol.DataType)\n    throw new InvalidOperationException($\"Column types differ: {leftCol.DataType} vs {rightCol.DataType}; convert first.\");","typeGuard":"static bool SameTypedColumns(DataFrameColumn a, DataFrameColumn b) => a?.DataType == b?.DataType;","tryCatchPattern":"try\n{\n    MergeColumns(left, right);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"other\" && ex.Message.Contains(\"type\"))\n{\n    // fall back: convert right column to left.DataType and retry\n}","preventionTips":["Compare DataType before any cross-column operation","Use a shared schema when loading multiple data sources","Write a helper that converts a column to a target Type once and reuse it"],"tags":["dotnet","dataframe","type-mismatch","argument-validation"],"backgroundTag":"type-mismatch","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}