{"record":{"id":"76f9005cfae11738","repo":"dotnet/machinelearning","slug":"strings-mapindicesexceedscolumnlength","errorCode":null,"errorMessage":"Strings.MapIndicesExceedsColumnLength","messagePattern":"Strings\\.MapIndicesExceedsColumnLength","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameColumns/ArrowStringDataFrameColumn.cs","lineNumber":422,"sourceCode":"                    clone = CloneImplementation(mapIndices as PrimitiveDataFrameColumn<int>, invertMapIndices);\n                else\n                    clone = CloneImplementation(mapIndices as PrimitiveDataFrameColumn<bool>);\n\n                for (long i = 0; i < numberOfNullsToAppend; i++)\n                    clone.Append(default);\n            }\n            else\n            {\n                clone = Clone(numberOfNullsToAppend);\n            }\n\n            return clone;\n        }\n\n        private ArrowStringDataFrameColumn CloneImplementation(PrimitiveDataFrameColumn<bool> boolColumn)\n        {\n            if (boolColumn.Length > Length)\n                throw new ArgumentException(Strings.MapIndicesExceedsColumnLength, nameof(boolColumn));\n\n            ArrowStringDataFrameColumn ret = new ArrowStringDataFrameColumn(Name);\n            for (long i = 0; i < boolColumn.Length; i++)\n            {\n                bool? value = boolColumn[i];\n                if (value == true)\n                    ret.Append(IsValid(i) ? GetBytes(i) : default(ReadOnlySpan<byte>));\n            }\n            return ret;\n        }\n\n        private ArrowStringDataFrameColumn CloneImplementation(PrimitiveDataFrameColumn<int> mapIndices, bool invertMapIndices)\n        {\n            ArrowStringDataFrameColumn ret = new ArrowStringDataFrameColumn(Name);\n\n            for (long i = 0; i < mapIndices.Length; i++)\n            {\n                int? index = mapIndices[invertMapIndices ? mapIndices.Length - 1 - i : i];","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameColumns/ArrowStringDataFrameColumn.cs#L404-L440","documentation":"The boolean-index CloneImplementation requires the bool filter column to be no longer than the string column being cloned; every bool element maps to one row. If boolColumn.Length > Length, some filter entries would address nonexistent rows, so an ArgumentException (message Strings.MapIndicesExceedsColumnLength) is thrown on the boolColumn argument.","triggerScenarios":"Calling Clone(boolFilterColumn) on an ArrowStringDataFrameColumn when the filter column has more elements than the column has rows, typically after the column was truncated/filtered but the mask was built from a longer original.","commonSituations":"Reusing a stale boolean mask from before rows were dropped; building a mask from the full DataFrame while cloning a filtered sub-column; off-by-one padding of the mask.","solutions":["Rebuild the boolean mask from the same (current) column/DataFrame being cloned.","Trim the mask: pass a Filter-style column of exactly Length or fewer elements.","Check boolColumn.Length <= column.Length before calling Clone.","Recompute the mask against the original data and apply your other filters to the result instead of to the mask."],"exampleFix":"// before\ncol.Clone(longMask); // longMask.Length > col.Length\n// after\nvar trimmed = new PrimitiveDataFrameColumn<bool>(\"mask\", longMask.Take((int)col.Length));\ncol.Clone(trimmed);","handlingStrategy":"validation","validationCode":"if (boolColumn.Length > column.Length)\n    throw new ArgumentException($\"Filter column length {boolColumn.Length} exceeds column length {column.Length}\", nameof(boolColumn));","typeGuard":null,"tryCatchPattern":"try { var clone = col.Clone(mask); }\ncatch (ArgumentException ex) when (ex.ParamName == \"boolColumn\") { /* rebuild mask from current column length */ }","preventionTips":["Derive boolean masks from the same column/DataFrame instance you clone","Re-create masks after any row-dropping operations","Assert mask length <= column length before cloning"],"tags":["dotnet","dataframe","argument-validation"],"backgroundTag":"argument-out-of-range","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}