dotnet/machinelearning · error · ArgumentException

Strings.MapIndicesExceedsColumnLength

Error message

Strings.MapIndicesExceedsColumnLength

What it means

CloneImplementation(boolColumn) uses the boolean column as a mask over this column; if the mask is longer than the column the mapping is undefined, so ArgumentException(MapIndicesExceedsColumnLength) is thrown.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/StringDataFrameColumn.cs:329

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

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

            return clone;
        }

        private StringDataFrameColumn CloneImplementation(PrimitiveDataFrameColumn<bool> boolColumn)
        {
            if (boolColumn.Length > Length)
                throw new ArgumentException(Strings.MapIndicesExceedsColumnLength, nameof(boolColumn));
            StringDataFrameColumn ret = new StringDataFrameColumn(Name, 0);
            for (long i = 0; i < boolColumn.Length; i++)
            {
                bool? value = boolColumn[i];
                if (value.HasValue && value.Value)
                    ret.Append(this[i]);
            }
            return ret;
        }

        private StringDataFrameColumn CloneImplementation(PrimitiveDataFrameColumn<int> mapIndices, bool invertMapIndices = false)
        {
            mapIndices = mapIndices ?? throw new ArgumentNullException(nameof(mapIndices));
            var ret = new StringDataFrameColumn(Name, mapIndices.Length);

            long rowIndex = 0;
            for (int b = 0; b < mapIndices.ColumnContainer.Buffers.Count; b++)
            {

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Trim the bool mask to the column's length before cloning
  2. Verify mask.Length == column.Length (or <=) before calling Clone
  3. Recompute the mask against the current column
  4. Slice the mask to match: clone only the first N mask entries if intentional

Example fix

// before
column.Clone(maskThatIsLonger);
// after
if (maskThatIsLonger.Length > column.Length)
    maskThatIsLonger = maskThatIsLonger.Slice(0, column.Length);
column.Clone(maskThatIsLonger);
Defensive patterns

Strategy: validation

Validate before calling

if (boolColumn.Length > column.Length) throw new ArgumentException("Mask longer than column");

Type guard

bool MaskFitsColumn(PrimitiveDataFrameColumn<bool> mask, long length) => mask.Length <= length;

Try / catch

try { var clone = column.Clone(mask); } catch (ArgumentException) { /* slice mask and retry */ }

Prevention

When it happens

Trigger: Calling Clone(boolMask) where boolMask.Length > column.Length; using a mask built for a longer DataFrame/column.

Common situations: Filtering a column with a predicate mask computed against a different (larger) dataset; reusing a cached mask after the source shrank.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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