dotnet/machinelearning · error · ArgumentException

Parameter must not be null, empty, or whitespace

Error message

Parameter must not be null, empty, or whitespace

What it means

Thrown by DataFrame.Melt when the variableName argument is null, empty, or whitespace. Melt reshapes wide data into long format and needs a valid name for the new 'variable' column it creates. The guard raises ArgumentException with Strings.ParameterMustNotBeNullOrWhitespace.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrame.cs:743

        /// // |----|-------|------|-------|
        /// // | 1  | Alice | 2020 | 100   |
        /// // | 2  | Bob   | 2020 | 200   |
        /// // | 1  | Alice | 2021 | 110   |
        /// // | 2  | Bob   | 2021 | 210   |
        /// // | 1  | Alice | 2022 | 120   |
        /// // | 2  | Bob   | 2022 | 220   |
        /// </code>
        /// </example>
        /// <remarks>
        /// Note: The output rows are ordered by value column (all rows for the first value column,
        /// then all rows for the second, etc.), which differs from pandas.melt() which orders by
        /// source row.
        /// </remarks>
        public DataFrame Melt(IEnumerable<string> idColumns, IEnumerable<string> valueColumns = null, string variableName = "variable", string valueName = "value", bool dropNulls = false)
        {
            if (string.IsNullOrWhiteSpace(variableName))
            {
                throw new ArgumentException(Strings.ParameterMustNotBeNullOrWhitespace, nameof(variableName));
            }

            if (string.IsNullOrWhiteSpace(valueName))
            {
                throw new ArgumentException(Strings.ParameterMustNotBeNullOrWhitespace, nameof(valueName));
            }

            if (idColumns == null)
            {
                throw new ArgumentNullException(nameof(idColumns));
            }

            var idColumnList = idColumns.ToList();

            HashSet<string> idColumnSet = null;

            if (valueColumns is null)
            {

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Pass a non-empty non-whitespace variableName, e.g. "variable"
  2. Omit the argument entirely to use the default value "variable"
  3. Trim/default the value at the call site if it comes from user input or config

Example fix

// before
df.Melt(ids, values, variableName: "");
// after
df.Melt(ids, values, variableName: "variable");
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(variableName)) variableName = "variable";

Try / catch

try { df.Melt(ids, values, variableName); }
catch (ArgumentException ex) when (ex.ParamName == "variableName") { /* supply default and retry */ }

Prevention

When it happens

Trigger: Calling df.Melt(idColumns, valueColumns, variableName: "", ...) or with variableName: null or a whitespace string such as " ".

Common situations: Programmatically building melt arguments from config where an optional setting resolves to empty string; users forgetting that variableName has a default but explicitly passing empty to override it.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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