dotnet/machinelearning · error · ArgumentException

String.Format(Strings.MismatchedValueType…

Error message

String.Format(Strings.MismatchedValueType, Strings.NumericColumnType)

What it means

Clone with a generic unmanaged mapIndices column requires the indices to be numeric (int/long-style select/reorder map). Non-numeric unmanaged columns (e.g. bool already handled separately, or an unexpected type) make IsNumericColumn() false and throw ArgumentException naming the mapIndices parameter.

Solutions

  1. Pass a long or int PrimitiveDataFrameColumn as mapIndices
  2. Convert custom unmanaged columns to long indices before cloning
  3. Use the bool-column overload when the intent is a row filter mask

Example fix

// before
col.Clone(charIndices); // non-numeric map
// after
var longIdx = new PrimitiveDataFrameColumn<long>("idx");
for (long i = 0; i < charIndices.Length; i++) longIdx.Append(charIndices[i]);
col.Clone(longIdx);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!mapIndices.IsNumericColumn()) throw new ArgumentException("mapIndices must be a numeric column");

Type guard

bool isNumericMap(DataFrameColumn c) => c.IsNumericColumn();

Try / catch

try { var clone = column.Clone(mapIndices); } catch (ArgumentException) { /* convert to long indices */ }

Prevention

When it happens

Trigger: Calling the private CloneImplementation<U> path (via Clone) with a non-numeric PrimitiveDataFrameColumn<U> that isn't bool, so the generic numeric-index overload receives a non-numeric column.

Common situations: Custom unmanaged struct types or char columns passed as map indices through generic code paths.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs:479

        {
            if (boolColumn.Length > Length)
                throw new ArgumentException(Strings.MapIndicesExceedsColumnLength, nameof(boolColumn));
            PrimitiveDataFrameColumn<T> ret = CreateNewColumn(Name);

            for (long i = 0; i < boolColumn.Length; i++)
            {
                bool? value = boolColumn[i];
                if (value.HasValue && value.Value == true)
                    ret.Append(this[i]);
            }
            return ret;
        }

        private PrimitiveDataFrameColumn<T> CloneImplementation<U>(PrimitiveDataFrameColumn<U> mapIndices, bool invertMapIndices = false)
            where U : unmanaged
        {
            if (!mapIndices.IsNumericColumn())
                throw new ArgumentException(String.Format(Strings.MismatchedValueType, Strings.NumericColumnType), nameof(mapIndices));

            PrimitiveColumnContainer<T> retContainer;
            if (mapIndices.DataType == typeof(long))
            {
                retContainer = _columnContainer.Clone(mapIndices._columnContainer, typeof(long), invertMapIndices);
            }
            else if (mapIndices.DataType == typeof(int))
            {
                retContainer = _columnContainer.Clone(mapIndices._columnContainer, typeof(int), invertMapIndices);
            }
            else
                throw new NotImplementedException();

            PrimitiveDataFrameColumn<T> ret = CreateNewColumn(Name, retContainer);
            return ret;
        }

        public PrimitiveDataFrameColumn<T> Clone(PrimitiveDataFrameColumn<long> mapIndices, bool invertMapIndices = false)

View on GitHub (pinned to 7b76e69cf9)