dotnet/machinelearning · error · ArgumentException
Strings.MismatchedColumnLengths
Error message
Strings.MismatchedColumnLengths
What it means
Binary arithmetic between two DecimalDataFrameColumn operands requires both columns to have the same number of rows, since the operation is applied element-wise. When the operand column's Length differs from this column's Length, HandleOperationImplementation throws ArgumentException with paramName `column` and message Strings.MismatchedColumnLengths.
Source
Thrown at src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperationImplementations.Exploded.cs:22
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// Generated from DataFrameColumn.BinaryOperationImplementations.ExplodedColumns.tt. Do not modify directly
using System;
using System.Collections.Generic;
namespace Microsoft.Data.Analysis
{
public partial class DecimalDataFrameColumn
{
//Binary Operations
internal DecimalDataFrameColumn HandleOperationImplementation(BinaryOperation operation, DecimalDataFrameColumn column, bool inPlace = false)
{
if (column.Length != Length)
{
throw new ArgumentException(Strings.MismatchedColumnLengths, nameof(column));
}
var newColumn = inPlace ? this : (DecimalDataFrameColumn)Clone();
newColumn.ColumnContainer.HandleOperation(operation, column.ColumnContainer);
return newColumn;
}
//Binary Scalar Operations
internal DecimalDataFrameColumn HandleOperationImplementation(BinaryOperation operation, decimal right, bool inPlace = false)
{
var newColumn = inPlace ? this : (DecimalDataFrameColumn)Clone();
newColumn.ColumnContainer.HandleOperation(operation, right);
return newColumn;
}
internal DecimalDataFrameColumn HandleReverseOperationImplementation(BinaryOperation operation, decimal right, bool inPlace = false)
{
var newColumn = inPlace ? this : (DecimalDataFrameColumn)Clone();
newColumn.ColumnContainer.HandleReverseOperation(operation, right);View on GitHub (pinned to 7b76e69cf9)
Solutions
- Before the operation, verify column.Length == thisColumn.Length; if not, align the data (filter, slice, or join) so both have the same rows.
- Ensure both columns come from the same DataFrame or were derived with the same row selection.
- For scalar/element-wise math on mismatched columns, first truncate the longer column to the shorter length via slicing/cloning.
Example fix
// before
var result = price * qty; // price.Length == 100, qty.Length == 90
// after
if (price.Length != qty.Length)
throw new InvalidOperationException("Align columns before arithmetic");
var result = price * qty; Defensive patterns
Strategy: validation
Validate before calling
if (left.Length != right.Length) throw new InvalidOperationException($"Column length mismatch: {left.Length} vs {right.Length}"); Type guard
static bool SameLength(DecimalDataFrameColumn a, DecimalDataFrameColumn b) => a.Length == b.Length;
Try / catch
try { var result = left * right; }
catch (ArgumentException ex) when (ex.Message == Strings.MismatchedColumnLengths || ex.ParamName == "column")
{
// align/slice columns and retry
} Prevention
- Derive operand columns from the same DataFrame
- Check Length equality in a helper before any column arithmetic
- After filtering, re-derive all dependent columns together
When it happens
Trigger: Calling Add/Subtract/Multiply/Divide/Modulo (or the +,-,*,/,% operators) on two DecimalDataFrameColumn instances of different Length, optionally with inPlace: true.
Common situations: Arithmetic between columns from different DataFrames with different row counts, after filtering one DataFrame but not the other, or mixing a full column with a sliced column.
Related errors
- The method or operation is not implemented.
- Strings.MismatchedColumnLengths
- string.Format(Strings.MismatchedValueType, typeof(string))
- String.Format(Strings.MultipleMismatchedValueType, typeof(lo
- Strings.MapIndicesExceedsColumnLength
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/f7a28a965485751d.
Report an issue: GitHub.