dotnet / dotnet/machinelearning

Incorrect throwing during data loading

Open
#2,389 4 comments 2 reactions 0 assignees View on GitHub
area-Core bug enhancement Priority:2
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

### System information

- Win10
- .NET Core 2.1/3.0 Preview 2

### Issue

Let's say we do loading of data from CSV file using simple POCO class and forget to add `LoadColumn` attribute on the properties. Then call to `CreateTextLoader/CreateTextReader` fails with NullReferenceException

```
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.ML.Data.TextLoader.CreateTextReader[TInput](IHostEnvironment host, Boolean hasHeader, Char separator, Boolean allowQuotedStrings, Boolean supportSparse, Boolean trimWhitespace)
at MLConsoleApp1.Program.Main(String[] args) in MLConsoleApp1\Program.cs:line 54
```

which definitely not user friendly. I track down that to line https://github.com/dotnet/machinelearning/blob/master/src/Microsoft.ML.Data/DataLoadSave/Text/TextLoader.cs#L1344

where you delegate assertion to IHostEnvironment since I running LocalEnvironment, I believe that by default when running in Local environment proper default behavior would be just throw. Right now I could not even imaging that such big usability mistake was made by MS, so I have to manually clone project and compile it locally to track down this error.

### Source code / logs

```
public class SentimentRow
{
public bool Sentiment { get; set; }

public string SentimentText { get; set; }
}
...
var mlContext = new MLContext();
var reader = mlContext.Data.CreateTextLoader(hasHeader: true);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.