Skip to content

Replacing TryGetColumnIndex with invocations of GetColumnOrNull #2088

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 3 commits into from
Jan 10, 2019

Conversation

sfilipi
Copy link
Member

@sfilipi sfilipi commented Jan 9, 2019

Work towards #1500 by removing references of TryGetColumnIndex, and replacing them with GetColumnOrNull in a few projects.

MetadataUtils.TryGetCategoricalFeatureIndices(_data.Schema.Schema, featureIndex, out _catsMap);
var featureCol = _data.Schema.Schema.GetColumnOrNull(DefaultColumnNames.Features);
ch.Assert(featureCol.HasValue);
MetadataUtils.TryGetCategoricalFeatureIndices(_data.Schema.Schema, featureCol.Value.Index, out _catsMap);
Copy link
Contributor

@TomFinley TomFinley Jan 9, 2019

Choose a reason for hiding this comment

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

In this particular case, you are asserting that it has a value, which is fine, but if the purpose is to just to clarify this, you could probably just get away with just doing .Value at the end and operating over that, since that also clarifies, "yes, I definitely expect this to have a value." #Resolved

int predictedLabelCol;
if (!input.Data.Schema.TryGetColumnIndex(input.PredictedLabelColumn, out predictedLabelCol))
var predictedLabelCol = input.Data.Schema.GetColumnOrNull(input.PredictedLabelColumn);
if (!predictedLabelCol.HasValue)
throw host.Except($"Column '{input.PredictedLabelColumn}' not found.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Except [](start = 27, length = 6)

I'm not sure if you want to do this at the same time, but in the general movement to start using ExceptSchemaMismatch to ensure greater uniformity between error messages, you might consider doing that transition at the same time. But, not sure if you want to.

@@ -381,9 +381,12 @@ private static void GetColTypesAndIndex(IHostEnvironment env, IDataView inputDat

for (int i = 0; i < columns.Length; i++)
{
if (!inputSchema.TryGetColumnIndex(columns[i].Input, out cols[i]))
var col = inputSchema.GetColumnOrNull(columns[i].Input);
if (!col.HasValue)
throw env.ExceptSchemaMismatch(nameof(inputSchema), "input", columns[i].Input);
Copy link
Contributor

@TomFinley TomFinley Jan 9, 2019

Choose a reason for hiding this comment

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

ExceptSchemaMismatch [](start = 30, length = 20)

This would be an example of a current existing usage of ExceptSchemaMismatch, perhaps a pattern to follow in the other places where we are currently using Except. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool!


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

trainData.Schema.Schema.TryGetColumnIndex(DefaultColumnNames.Features, out int featureIndex);
MetadataUtils.TryGetCategoricalFeatureIndices(trainData.Schema.Schema, featureIndex, out categoricalFeatures);
var featureCol = trainData.Schema.Schema.GetColumnOrNull(DefaultColumnNames.Features);
ch.Assert(featureCol.HasValue);
Copy link
Contributor

@TomFinley TomFinley Jan 9, 2019

Choose a reason for hiding this comment

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

ch.Assert(featureCol.HasValue); [](start = 16, length = 31)

Similar note, can probably just use .Value in the line above to clarify "yes I expect this to have a value." But, as you like. #Resolved

@TomFinley
Copy link
Contributor

TomFinley commented Jan 9, 2019

Looks more or less good @sfilipi ! One thing though, you seem to be when you definitely know the column is there, still using this OrNull facility. Would it not be more appropriate, as we do elsewhere, to use this facility?

public Column this[string name]

This would be simpler, and possibly more idiomatic with much of our usage elsewhere. What do you think? #Resolved

Copy link
Contributor

@TomFinley TomFinley left a comment

Choose a reason for hiding this comment

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

Looks good @sfilipi , just a few minor notes I don't completely insist on, only things to think about and do if you agree.

Copy link
Member

@wschin wschin left a comment

Choose a reason for hiding this comment

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

:shipit:

@sfilipi
Copy link
Member Author

sfilipi commented Jan 10, 2019

Good point! thanks for suggesting it!


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

@sfilipi sfilipi merged commit 512c4cd into dotnet:master Jan 10, 2019
@sfilipi sfilipi deleted the tryGetIndexCleanup branch March 13, 2019 18:08
@ghost ghost locked as resolved and limited conversation to collaborators Mar 25, 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