Skip to content

Add convenience constructors for TextLoader. #698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 22, 2018

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Aug 20, 2018

Creating a TextLoader and specifying its arguments manually is too verbose. We should add a few constructor overloads to make it easier.

This work item is related to the new API proposal #371

Creating a TextLoader and specifying its arguments manually is too verbose. We should add a few constructor overloads to make it easier.
: this(name, type, new[] { new Range(index) }) { }

public Column(string name, DataKind? type = null, Range[] source = null, KeyRange keyRange = null)
{
Copy link
Contributor

@Zruty0 Zruty0 Aug 20, 2018

Choose a reason for hiding this comment

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

{ [](start = 12, length = 1)

Contracts.CheckValue(name, nameof(name)); Contracts.CheckValueOrNull(everything_else);

Also, what's up with range being nullable?
#Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Which range? source or keyRange?

Both of them can be null today.


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

Copy link
Contributor

@Zruty0 Zruty0 Aug 21, 2018

Choose a reason for hiding this comment

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

I meant source. What does source=null signify?


In reply to: 211438122 [](ancestors = 211438122,211433252)

Copy link
Member Author

Choose a reason for hiding this comment

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

It was supposed to mean, "I haven't set it yet". Just like if you say:

new TextLoader.Column() { Name = "foo" }

today.

At first, I meant these constructors to be as non-prescriptive as the current parameterless constructors are. And the validation only happens once you actually use the object. But since we are adding Contracts checks into them, that reasoning probably doesn't hold anymore.

I'll remove the default null value for source, and will also need to remove it for type.

Copy link
Contributor

@Zruty0 Zruty0 Aug 21, 2018

Choose a reason for hiding this comment

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

Oh, I see. Well, I like it better this way. We didn't have 'dual-initialized' objects before in our codebase (either the ctor was completely empty, or it would always construct a valid immutable object), so there's no standard practice to follow in this case.

For the self-documentation purpose, also add Contracts.CheckValueOrNull(type)


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

Copy link
Member Author

Choose a reason for hiding this comment

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

For the self-documentation purpose, also add Contracts.CheckValueOrNull(type)

That isn't possible since CheckValueOrNull has a class generic constraint, and type is a Nullable<DataKind>

@@ -179,6 +192,14 @@ public bool IsValid()

public sealed class Range
{
public Range() { }

public Range(int index)
Copy link
Contributor

@Zruty0 Zruty0 Aug 20, 2018

Choose a reason for hiding this comment

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

Range [](start = 19, length = 5)

Does it make sense to add a ctor that takes min and max? #Closed

public Range() { }

public Range(int index)
{
Copy link
Contributor

@Zruty0 Zruty0 Aug 20, 2018

Choose a reason for hiding this comment

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

{ [](start = 11, length = 2)

Contracts.CheckParam(index >=0 ... #Closed

Copy link
Contributor

@Zruty0 Zruty0 left a comment

Choose a reason for hiding this comment

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

:shipit:

@eerhardt
Copy link
Member Author

test OSX10.13 Debug

Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka left a comment

Choose a reason for hiding this comment

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

:shipit:

@eerhardt eerhardt merged commit 2f4e50d into dotnet:master Aug 22, 2018
@eerhardt eerhardt deleted the TextLoaderCtors branch August 22, 2018 17:19
@ghost ghost locked as resolved and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants