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'.

Solutions

  1. Remove the duplicated names from valueColumns (or idColumns) so the lists are disjoint
  2. Compute valueColumns as the set difference of the desired columns and idColumns
  3. 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

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.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: 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)