dotnet/machinelearning · error · NotImplementedException
nameof(TKey)
Error message
nameof(TKey)
What it means
Marks the not-implemented branch in StringDataFrameColumn's grouped-indices method (the typed GetGroupedIndices<TKey> path). Grouping is only implemented for TKey = string, because values are bucketed via a string multimap; any other key type falls into the NotImplementedException that names nameof(TKey) as the offending parameter.
Solutions
- Use one of the supported TKey types (e.g. long, int, string, bool, DateTime per the API docs)
- Pre-convert the key column to a supported primitive type before grouping
- Implement custom grouping with LINQ GroupBy if the key type is unsupported
- Check the source for the supported TKey set and match it
Example fix
// before var grouped = column.GetGroupedIndices<MyKey>(...); // after var grouped = column.GetGroupedIndices<long>(key => key.GetHashCode());
Defensive patterns
Strategy: validation
Validate before calling
if (!(typeof(TKey) == typeof(long) || typeof(TKey) == typeof(int) || typeof(TKey) == typeof(string) || typeof(TKey) == typeof(bool)))
throw new NotSupportedException($"TKey {typeof(TKey)} not supported for grouping"); Type guard
bool IsSupportedKeyType<TKey>() => typeof(TKey) == typeof(long) || typeof(TKey) == typeof(int) || typeof(TKey) == typeof(bool);
Try / catch
try { column.GetGroupedIndices<TKey>(...); } catch (NotImplementedException) { /* fall back to LINQ GroupBy */ } Prevention
- Stick to primitive TKey types documented for grouping APIs
- Check the library source/docs for the supported key set
- Use LINQ GroupBy for custom key types
When it happens
Trigger: Calling GetGroupedIndices<TKey> (or similar grouping API) with an unsupported key type such as a custom class, Guid, or short.
Common situations: Grouping by an unexpected key type inferred from generics; migrating code that assumed arbitrary key types are supported.
Related errors
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/2c50eb6c856c5c4c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/StringDataFrameColumn.cs:438
if (containsKey)
{
values.Add(i);
}
else
{
multimap.Add(str, new List<long>() { i });
}
}
else
{
nullIndices.Add(i);
}
}
return multimap as Dictionary<TKey, ICollection<long>>;
}
else
{
throw new NotImplementedException(nameof(TKey));
}
}
/// <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 StringDataFrameColumn FillNulls(string value, bool inPlace = false)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
StringDataFrameColumn column = inPlace ? this : Clone();
for (long i = 0; i < column.Length; i++)
{
if (column[i] == null)View on GitHub (pinned to 7b76e69cf9)