dotnet/machinelearning · error · ArgumentException
Columns cannot exist in both idColumns and valueColumns
Error message
Columns cannot exist in both idColumns and valueColumns
What it means
Thrown by DataFrame.Melt when a column name appears in both idColumns and valueColumns. A column cannot simultaneously be kept as an identifier and melted as a value; the library rejects the overlap with ArgumentException (Strings.DuplicateColumnsInIdAndValueLists) on 'valueColumns'.
Source
Thrown at src/Microsoft.Data.Analysis/DataFrame.cs:783
var valueColumnList = valueColumns?.ToList()
?? _columnCollection
.Where(c => !idColumnSet.Contains(c.Name))
.Select(c => c.Name)
.ToList();
if (idColumnList.Count == 0)
{
throw new ArgumentException(Strings.MissingIdColumns, nameof(idColumns));
}
if (valueColumns != null && valueColumnList.Count == 0)
{
throw new ArgumentException(Strings.MissingValueColumns, nameof(valueColumns));
}
if (valueColumns != null && valueColumnList.Any(v => idColumnList.Contains(v)))
{
throw new ArgumentException(Strings.DuplicateColumnsInIdAndValueLists, nameof(valueColumns));
}
if (valueColumns == null && valueColumnList.Count == 0)
{
throw new InvalidOperationException(Strings.NoValueColumnsRemaining);
}
if (_columnCollection.IndexOf(variableName) >= 0)
{
throw new ArgumentException(string.Format(Strings.VariableNameAlreadyExists, variableName), nameof(variableName));
}
if (_columnCollection.IndexOf(valueName) >= 0)
{
throw new ArgumentException(string.Format(Strings.ValueNameAlreadyExists, valueName), nameof(valueName));
}
if (string.Equals(variableName, valueName))View on GitHub (pinned to 7b76e69cf9)
Solutions
- Remove the duplicated names from valueColumns (or idColumns) so the lists are disjoint
- Compute valueColumns as the set difference of the desired columns and idColumns
- Deduplicate/intersect-check the two lists before calling Melt
Example fix
// before
df.Melt(new[] { "Id", "Sales" }, new[] { "Sales", "Cost" });
// after
df.Melt(new[] { "Id" }, new[] { "Sales", "Cost" }); Defensive patterns
Strategy: validation
Validate before calling
var dupes = valueColumnList.Intersect(idColumnList).ToList();
if (dupes.Any()) throw new InvalidOperationException($"In both lists: {string.Join(",", dupes)}"); Try / catch
try { df.Melt(ids, values); }
catch (ArgumentException ex) when (ex.ParamName == "valueColumns" && ex.Message.Contains("both")) { /* deduplicate and retry */ } Prevention
- Compute valueColumns as set difference from idColumns
- Use HashSet-based selection so lists stay disjoint
- Add a pre-call intersection check in pipelines
When it happens
Trigger: Calling df.Melt(new[]{"Id","Sales"}, new[]{"Sales"}) — any name present in both lists; usually from overlapping user selections or generated lists without deduplication.
Common situations: Dynamic dashboards where users multi-select columns for both groups; building the lists from overlapping queries; copy-paste errors in hardcoded lists.
Related errors
- Parameter must not be null, empty, or whitespace
- Value cannot be null. (Parameter 'idColumns')
- Must provide at least 1 ID column
- Must provide at least 1 value column when specifying value c
- There are no columns in the DataFrame to use as value column
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/4f503e5329e80473.
Report an issue: GitHub.