dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
8.94k stars 1.86k forks source link

[DataFrame] Null Reference on ElementwiseEquals on DateTime columns from DataFrame #6829

Closed novelhawk closed 9 months ago

novelhawk commented 10 months ago

System Information (please complete the following information):

Describe the bug Invoking ElementwiseEquals on a PrimitiveDataFrameColumn obtained by accessing DataFrame["ColumnName"] throws NullReferenceException

To Reproduce

  1. Create a PrimitiveDataFrameColumn with some values
  2. Create a dataframe with the column using its constructor
  3. Access the dataframe's column by using the this[string column] getter, es: df["ColumnName"]
  4. Call the ElementwiseEquals method on the column obtained through the DataFrame
  5. Observe that a NullReferenceException is thrown.
  6. Call the same method on the column passed to the DataFrame constructor.
  7. Observe that no exceptions are thrown

Expected behavior df["Test"] should behave like column and should not throw exceptions.

Screenshots, Code, Sample Projects Reproduction example:

#r "nuget: Microsoft.Data.Analysis, 0.20.1"
using Microsoft.Data.Analysis;

var column = new DateTimeDataFrameColumn("Test");
column.Append(DateTime.Today);
var df = new DataFrame(column);
Console.WriteLine(column == df["Test"]); // true
Console.WriteLine(column.ElementwiseEquals(DateTime.Today).Any()); // True
df["Test"].ElementwiseEquals(DateTime.Today) // Throws NullReferenceException

Stack trace Error: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Data.Analysis.PrimitiveDataFrameColumn1.ElementwiseEqualsImplementation[U](U value) at Microsoft.Data.Analysis.PrimitiveDataFrameColumn1.ElementwiseEquals[U](U value) at Submission#6.<>d__0.MoveNext() --- End of stack trace from previous location --- at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray1 precedingExecutors, Func2 currentExecutor, StrongBox1 exceptionHolderOpt, Func2 catchExceptionOpt, CancellationToken cancellationToken)