dotnet/machinelearning · error · System.ArgumentNullException

Value cannot be null. (Parameter 'other')

Error message

Value cannot be null. (Parameter 'other')

What it means

DataFrame.Merge throws ArgumentNullException immediately when the `other` DataFrame is null. The library requires a concrete right-hand DataFrame to compute join row-index mappings, so it validates the argument before any join algorithm runs. The message names the offending parameter ('other').

Source

Thrown at src/Microsoft.Data.Analysis/DataFrame.Join.cs:334

                    }
                }
                else
                {
                    foreach (long row in supplementaryJoinColumnsNullIndices)
                    {
                        retainedRowIndices.Append(i);
                        supplementaryRowIndices.Append(row);
                    }
                }
            }

            return intersection;
        }

        public DataFrame Merge(DataFrame other, string[] leftJoinColumns, string[] rightJoinColumns, string leftSuffix = "_left", string rightSuffix = "_right", JoinAlgorithm joinAlgorithm = JoinAlgorithm.Left)
        {
            if (other == null)
                throw new ArgumentNullException(nameof(other));

            // In Outer join the joined dataframe retains each row — even if no other matching row exists in supplementary dataframe.
            // Outer joins subdivide further into left outer joins (left dataframe is retained), right outer joins (rightdataframe is retained), in full outer both are retained

            PrimitiveDataFrameColumn<long> retainedRowIndices;
            PrimitiveDataFrameColumn<long> supplementaryRowIndices;
            DataFrame supplementaryDataFrame;
            DataFrame retainedDataFrame;
            bool isLeftDataFrameRetained;

            if (joinAlgorithm == JoinAlgorithm.Left || joinAlgorithm == JoinAlgorithm.Right)
            {
                isLeftDataFrameRetained = (joinAlgorithm == JoinAlgorithm.Left);

                supplementaryDataFrame = isLeftDataFrameRetained ? other : this;
                var supplementaryJoinColumns = isLeftDataFrameRetained ? rightJoinColumns : leftJoinColumns;

                retainedDataFrame = isLeftDataFrameRetained ? this : other;

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Ensure the `other` DataFrame is constructed/loaded before calling Merge (e.g. DataFrame.LoadCsv succeeded and was assigned).
  2. Guard the call: if (other == null) { load or substitute an empty DataFrame; } before merging.
  3. If the right side may legitimately be empty, pass new DataFrame() with the matching join columns instead of null.
  4. Catch ArgumentNullException to surface a clear message naming the missing dataset source.

Example fix

// before
DataFrame merged = orders.Merge(null, new[]{"Id"}, new[]{"OrderId"});
// after
if (right == null)
    throw new InvalidOperationException("Right dataset was not loaded");
DataFrame merged = orders.Merge(right, new[]{"Id"}, new[]{"OrderId"});
Defensive patterns

Strategy: validation

Validate before calling

if (other == null)
    throw new InvalidOperationException("Right DataFrame for Merge was not loaded");
// safe:
var merged = left.Merge(other, leftCols, rightCols);

Type guard

bool CanMerge(DataFrame other) => other is not null;

Try / catch

try { merged = left.Merge(other, lc, rc); }
catch (ArgumentNullException ex) { logger.LogError(ex, "Merge input null"); merged = left; }

Prevention

When it happens

Trigger: Calling df.Merge(null, leftJoinColumns, rightJoinColumns) — directly or via a variable that was never assigned, or the result of a lookup/API call that returned null — with any JoinAlgorithm (Left, Right, Outer).

Common situations: Loading the second dataset from a file or database that returned null on failure; a conditional pipeline where an optional enrichment DataFrame is absent; refactoring that renamed a field but left an old null-returning getter in place.

Related errors


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