dotnet/machinelearning · error · ArgumentException

Strings.MapIndicesExceedsColumnLength

Error message

Strings.MapIndicesExceedsColumnLength

What it means

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.

Solutions

  1. Rebuild the boolean mask from the same (current) column/DataFrame being cloned.
  2. Trim the mask: pass a Filter-style column of exactly Length or fewer elements.
  3. Check boolColumn.Length <= column.Length before calling Clone.
  4. Recompute the mask against the original data and apply your other filters to the result instead of to the mask.

Example fix

// before
col.Clone(longMask); // longMask.Length > col.Length
// after
var trimmed = new PrimitiveDataFrameColumn<bool>("mask", longMask.Take((int)col.Length));
col.Clone(trimmed);
Defensive patterns

Strategy: validation

Validate before calling

if (boolColumn.Length > column.Length)
    throw new ArgumentException($"Filter column length {boolColumn.Length} exceeds column length {column.Length}", nameof(boolColumn));

Try / catch

try { var clone = col.Clone(mask); }
catch (ArgumentException ex) when (ex.ParamName == "boolColumn") { /* rebuild mask from current column length */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/76f9005cfae11738. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/ArrowStringDataFrameColumn.cs:422

                    clone = CloneImplementation(mapIndices as PrimitiveDataFrameColumn<int>, invertMapIndices);
                else
                    clone = CloneImplementation(mapIndices as PrimitiveDataFrameColumn<bool>);

                for (long i = 0; i < numberOfNullsToAppend; i++)
                    clone.Append(default);
            }
            else
            {
                clone = Clone(numberOfNullsToAppend);
            }

            return clone;
        }

        private ArrowStringDataFrameColumn CloneImplementation(PrimitiveDataFrameColumn<bool> boolColumn)
        {
            if (boolColumn.Length > Length)
                throw new ArgumentException(Strings.MapIndicesExceedsColumnLength, nameof(boolColumn));

            ArrowStringDataFrameColumn ret = new ArrowStringDataFrameColumn(Name);
            for (long i = 0; i < boolColumn.Length; i++)
            {
                bool? value = boolColumn[i];
                if (value == true)
                    ret.Append(IsValid(i) ? GetBytes(i) : default(ReadOnlySpan<byte>));
            }
            return ret;
        }

        private ArrowStringDataFrameColumn CloneImplementation(PrimitiveDataFrameColumn<int> mapIndices, bool invertMapIndices)
        {
            ArrowStringDataFrameColumn ret = new ArrowStringDataFrameColumn(Name);

            for (long i = 0; i < mapIndices.Length; i++)
            {
                int? index = mapIndices[invertMapIndices ? mapIndices.Length - 1 - i : i];

View on GitHub (pinned to 7b76e69cf9)