dotnet/machinelearning · error · NotImplementedException

NotImplementedException

Error message

NotImplementedException

What it means

DataFrameColumn.ValueCounts is a virtual method on the abstract DataFrameColumn base class whose base implementation is a stub that always throws NotImplementedException. Only derived columns that override it (primitive column types in this library version) provide the actual unique-value counting; calling it on a column type that has not overridden the method surfaces the raw NotImplementedException.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrameColumn.cs:298

            var ret = new Dictionary<long, ICollection<long>>();

            //For each value in this column find rows from other column with equal value
            for (int i = 0; i < this.Length; i++)
            {
                var value = this[i];
                if (value != null && multimap.TryGetValue((TKey)value, out ICollection<long> otherRowIndices))
                {
                    ret.Add(i, otherRowIndices);
                }
            }

            return ret;
        }

        /// <summary>
        /// Returns a DataFrame containing counts of unique values
        /// </summary>
        public virtual DataFrame ValueCounts() => throw new NotImplementedException();

        public virtual GroupBy GroupBy(int columnIndex, DataFrame parent) => throw new NotImplementedException();

        /// <summary>
        /// Returns a new column with <see langword="null" /> elements replaced by <paramref name="value"/>.
        /// </summary>
        /// <remarks>Tries to convert value to the column's DataType</remarks>
        /// <param name="value"></param>
        /// <param name="inPlace">Indicates if the operation should be performed in place</param>
        public virtual DataFrameColumn FillNulls(object value, bool inPlace = false) => FillNullsImplementation(value, inPlace);

        protected abstract DataFrameColumn FillNullsImplementation(object value, bool inPlace);

        /// <summary>
        /// Returns a <see cref="DataFrameColumn"/> with no missing values.
        /// </summary>
        public virtual DataFrameColumn DropNulls() => DropNullsImplementation();

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Call ValueCounts only on column types known to implement it (e.g. PrimitiveDataFrameColumn<T>, StringDataFrameColumn).
  2. Check HasDescription()-style capability or wrap the call in try/catch for NotImplementedException and skip unsupported columns.
  3. If it is your own column subclass, override ValueCounts and return a DataFrame of value counts.
  4. Upgrade the Microsoft.Data.Analysis package — later versions implement this for more column types.

Example fix

// before
foreach (DataFrameColumn col in df.Columns)
    var counts = col.ValueCounts(); // throws for unsupported types
// after
foreach (DataFrameColumn col in df.Columns)
{
    try { var counts = col.ValueCounts(); }
    catch (NotImplementedException) { /* skip column type without ValueCounts */ }
}
Defensive patterns

Strategy: try-catch

Validate before calling

bool supported = col is PrimitiveDataFrameColumn<int> || col is PrimitiveDataFrameColumn<long> || col is PrimitiveDataFrameColumn<double> || col is PrimitiveDataFrameColumn<float> || col is StringDataFrameColumn;

Type guard

static bool SupportsValueCounts(DataFrameColumn c) =>
    c is PrimitiveDataFrameColumn<int> || c is PrimitiveDataFrameColumn<long> ||
    c is PrimitiveDataFrameColumn<float> || c is PrimitiveDataFrameColumn<double> ||
    c is StringDataFrameColumn;

Try / catch

try { var counts = col.ValueCounts(); }
catch (NotImplementedException)
{
    // column type does not support ValueCounts in this package version; skip or compute manually
}

Prevention

When it happens

Trigger: Calling column.ValueCounts() on a DataFrameColumn instance whose concrete type does not override ValueCounts (e.g. a custom column subclass, or a non-primitive column type).

Common situations: Writing generic code over DataFrameColumn collections in a DataFrame where some columns are custom or unsupported types; upgrading/downgrading Microsoft.Data.Analysis versions where override coverage changed; exploratory analysis calling ValueCounts on every column.

Related errors


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