Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Fix https://github.com/dotnet/corefxlab/issues/2906 - #2907

Merged
5 commits merged into
dotnet:masterfrom
pgovind:FixLoadCsvDataTypes
Apr 30, 2020
Merged

5 commits merged into
dotnet:masterfrom
pgovind:FixLoadCsvDataTypes

Conversation

@pgovind

@pgovind pgovind commented Apr 28, 2020 •

Copy link
Copy Markdown

We were dropping the column names when DataTypes was being passed in to LoadCsv.

I suggest looking at the diff with whitespace turned off

using (var streamReader = new StreamReader(csvStream, encoding ?? Encoding.UTF8, detectEncodingFromByteOrderMarks: true, DefaultStreamReaderBufferSize, leaveOpen: true))
{
string line = null;
if (dataTypes == null)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you remember why we were doing this in the first place? Or was this just a mistake?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of dataTypes being passed in, should we stop processing after the header row?


In reply to: 416981821 [](ancestors = 416981821)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I was wondering about it too. I think I was using dataTypes inside as part of "guessing" the types at one point. Either that or it was a mistake made from trying to optimize the csv read.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I fixed that, and found some other corner cases and added unit tests for them.

if ((numberOfRowsToRead == -1) || rowline < numberOfRowsToRead)
{
if ((numberOfRowsToRead == -1) || rowline < numberOfRowsToRead)
if (linesForGuessType.Count < guessRows || guessRows == 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the right check here:

if (linesForGuessType.Count < guessRows || (header && rowline == 0))

?

If guessRows == 0 and !header, then there is no reason to get here, right?

@pgovind pgovind Apr 30, 2020 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, your idea is better. The only other thing I had to do was to change(line 248)

 if (rowline == guessRows)
                    {
                        break;
                    }

to

 if (rowline == guessRows || guessRows == 0)
                    {
                        break;
                    }

Otherwise we'd end up reading the whole stream when guessRows = 0 unnecessarily.

@eerhardt eerhardt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor question on a check. Other than that, this looks good.

@ghost

ghost commented Apr 30, 2020

Copy link
Copy Markdown

Hello @pgovind!

Because this pull request has the Merge-When-Green label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost
ghost merged commit 300885c into dotnet:master Apr 30, 2020
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants