Skip to content

Commit 449719c

Browse files
authored
Enable MSML_PrivateFieldName for the full solution (#4835)
1 parent 6cd6081 commit 449719c

File tree

33 files changed

+363
-366
lines changed

33 files changed

+363
-366
lines changed

.editorconfig

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ dotnet_diagnostic.VSTHRD200.severity = none
1515
# MSML_GeneralName: This name should be PascalCased
1616
dotnet_diagnostic.MSML_GeneralName.severity = none
1717

18-
# MSML_PrivateFieldName: Private field name not in: _camelCase format
19-
dotnet_diagnostic.MSML_PrivateFieldName.severity = none
20-
2118
# MSML_NoBestFriendInternal: Cross-assembly internal access requires referenced item to have Microsoft.ML.BestFriendAttribute attribute.
2219
dotnet_diagnostic.MSML_NoBestFriendInternal.severity = none
2320

test/Microsoft.ML.AutoML.Tests/ConversionTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ namespace Microsoft.ML.AutoML.Test
1212

1313
public class ConversionTests
1414
{
15-
private readonly ITestOutputHelper output;
15+
private readonly ITestOutputHelper _output;
1616

1717
public ConversionTests(ITestOutputHelper output)
1818
{
19-
this.output = output;
19+
this._output = output;
2020
}
2121

2222
[Fact]
@@ -34,7 +34,7 @@ public void ConvertFloatMissingValues()
3434
{
3535
float value;
3636
var success = Conversions.Instance.TryParse(missingValue.AsMemory(), out value);
37-
output.WriteLine($"{missingValue} parsed as {value}");
37+
_output.WriteLine($"{missingValue} parsed as {value}");
3838
Assert.True(success);
3939
//Assert.Equal(float.NaN, value);
4040
}

test/Microsoft.ML.AutoML.Tests/UserInputValidationTests.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.ML.AutoML.Test
1313

1414
public class UserInputValidationTests
1515
{
16-
private static readonly IDataView Data = DatasetUtil.GetUciAdultDataView();
16+
private static readonly IDataView _data = DatasetUtil.GetUciAdultDataView();
1717

1818
[Fact]
1919
public void ValidateExperimentExecuteNullTrainData()
@@ -25,7 +25,7 @@ public void ValidateExperimentExecuteNullTrainData()
2525
[Fact]
2626
public void ValidateExperimentExecuteNullLabel()
2727
{
28-
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(Data,
28+
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(_data,
2929
new ColumnInformation() { LabelColumnName = null }, null, TaskKind.Regression));
3030

3131
Assert.Equal("Provided label column cannot be null", ex.Message);
@@ -36,7 +36,7 @@ public void ValidateExperimentExecuteLabelNotInTrain()
3636
{
3737
foreach (var task in new[] { TaskKind.Recommendation, TaskKind.Regression })
3838
{
39-
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(Data,
39+
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(_data,
4040
new ColumnInformation() { LabelColumnName = "L" }, null, task));
4141

4242
Assert.Equal("Provided label column 'L' not found in training data.", ex.Message);
@@ -51,7 +51,7 @@ public void ValidateExperimentExecuteNumericColNotInTrain()
5151

5252
foreach (var task in new[] { TaskKind.Recommendation, TaskKind.Regression })
5353
{
54-
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(Data, columnInfo, null, task));
54+
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(_data, columnInfo, null, task));
5555
Assert.Equal("Provided label column 'Label' was of type Boolean, but only type Single is allowed.", ex.Message);
5656
}
5757
}
@@ -62,7 +62,7 @@ public void ValidateExperimentExecuteNullNumericCol()
6262
var columnInfo = new ColumnInformation();
6363
columnInfo.NumericColumnNames.Add(null);
6464

65-
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(Data, columnInfo, null, TaskKind.Regression));
65+
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(_data, columnInfo, null, TaskKind.Regression));
6666
Assert.Equal("Null column string was specified as numeric in column information", ex.Message);
6767
}
6868

@@ -72,7 +72,7 @@ public void ValidateExperimentExecuteDuplicateCol()
7272
var columnInfo = new ColumnInformation();
7373
columnInfo.NumericColumnNames.Add(DefaultColumnNames.Label);
7474

75-
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(Data, columnInfo, null, TaskKind.Regression));
75+
var ex = Assert.Throws<ArgumentException>(() => UserInputValidationUtil.ValidateExperimentExecuteArgs(_data, columnInfo, null, TaskKind.Regression));
7676
}
7777

7878
[Fact]

test/Microsoft.ML.AutoML.Tests/Utils/TaskAgnosticAutoFit.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ public enum TaskType
2121
/// </summary>
2222
internal class TaskAgnosticAutoFit
2323
{
24-
private TaskType taskType;
25-
private MLContext context;
24+
private TaskType _taskType;
25+
private MLContext _context;
2626

2727
internal interface IUniversalProgressHandler : IProgress<RunDetail<RegressionMetrics>>, IProgress<RunDetail<MulticlassClassificationMetrics>>
2828
{
2929
}
3030

3131
internal TaskAgnosticAutoFit(TaskType taskType, MLContext context)
3232
{
33-
this.taskType = taskType;
34-
this.context = context;
33+
this._taskType = taskType;
34+
this._context = context;
3535
}
3636

3737
internal IEnumerable<TaskAgnosticIterationResult> AutoFit(
@@ -46,7 +46,7 @@ internal IEnumerable<TaskAgnosticIterationResult> AutoFit(
4646
{
4747
var columnInformation = new ColumnInformation() { LabelColumnName = label };
4848

49-
switch (this.taskType)
49+
switch (this._taskType)
5050
{
5151
case TaskType.Classification:
5252

@@ -58,7 +58,7 @@ internal IEnumerable<TaskAgnosticIterationResult> AutoFit(
5858
MaxModels = maxModels
5959
};
6060

61-
var classificationResult = this.context.Auto()
61+
var classificationResult = this._context.Auto()
6262
.CreateMulticlassClassificationExperiment(mcs)
6363
.Execute(
6464
trainData,
@@ -80,7 +80,7 @@ internal IEnumerable<TaskAgnosticIterationResult> AutoFit(
8080
MaxModels = maxModels
8181
};
8282

83-
var regressionResult = this.context.Auto()
83+
var regressionResult = this._context.Auto()
8484
.CreateRegressionExperiment(rs)
8585
.Execute(
8686
trainData,
@@ -102,7 +102,7 @@ internal IEnumerable<TaskAgnosticIterationResult> AutoFit(
102102
MaxModels = maxModels
103103
};
104104

105-
var recommendationResult = this.context.Auto()
105+
var recommendationResult = this._context.Auto()
106106
.CreateRecommendationExperiment(recommendationSettings)
107107
.Execute(
108108
trainData,
@@ -115,7 +115,7 @@ internal IEnumerable<TaskAgnosticIterationResult> AutoFit(
115115
return iterationResults;
116116

117117
default:
118-
throw new ArgumentException($"Unknown task type {this.taskType}.", "TaskType");
118+
throw new ArgumentException($"Unknown task type {this._taskType}.", "TaskType");
119119
}
120120
}
121121

@@ -135,11 +135,11 @@ internal ScoreResult Score(
135135

136136
result.ScoredTestData = model.Transform(testData);
137137

138-
switch (this.taskType)
138+
switch (this._taskType)
139139
{
140140
case TaskType.Classification:
141141

142-
var classificationMetrics = context.MulticlassClassification.Evaluate(result.ScoredTestData, labelColumnName: label);
142+
var classificationMetrics = _context.MulticlassClassification.Evaluate(result.ScoredTestData, labelColumnName: label);
143143

144144
//var classificationMetrics = context.MulticlassClassification.(scoredTestData, labelColumnName: label);
145145
result.PrimaryMetricResult = classificationMetrics.MicroAccuracy; // TODO: don't hardcode metric
@@ -149,15 +149,15 @@ internal ScoreResult Score(
149149

150150
case TaskType.Regression:
151151

152-
var regressionMetrics = context.Regression.Evaluate(result.ScoredTestData, labelColumnName: label);
152+
var regressionMetrics = _context.Regression.Evaluate(result.ScoredTestData, labelColumnName: label);
153153

154154
result.PrimaryMetricResult = regressionMetrics.RSquared; // TODO: don't hardcode metric
155155
result.Metrics = TaskAgnosticIterationResult.MetricValuesToDictionary(regressionMetrics);
156156

157157
break;
158158

159159
default:
160-
throw new ArgumentException($"Unknown task type {this.taskType}.", "TaskType");
160+
throw new ArgumentException($"Unknown task type {this._taskType}.", "TaskType");
161161
}
162162

163163
return result;

test/Microsoft.ML.AutoML.Tests/Utils/TaskAgnosticIterationResult.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal class TaskAgnosticIterationResult
2323
internal Pipeline Pipeline;
2424
internal int PipelineInferenceTimeInSeconds;
2525

26-
private string primaryMetricName;
26+
private string _primaryMetricName;
2727

2828
private TaskAgnosticIterationResult(RunDetail baseRunDetail, object validationMetrics, string primaryMetricName)
2929
{
@@ -34,7 +34,7 @@ private TaskAgnosticIterationResult(RunDetail baseRunDetail, object validationMe
3434
this.PipelineInferenceTimeInSeconds = (int)baseRunDetail.PipelineInferenceTimeInSeconds;
3535
this.RuntimeInSeconds = (int)baseRunDetail.RuntimeInSeconds;
3636

37-
this.primaryMetricName = primaryMetricName;
37+
this._primaryMetricName = primaryMetricName;
3838
this.PrimaryMetricValue = -1; // default value in case of exception. TODO: won't work for minimizing metrics, use nullable?
3939

4040
if (validationMetrics == null)
@@ -44,7 +44,7 @@ private TaskAgnosticIterationResult(RunDetail baseRunDetail, object validationMe
4444

4545
this.MetricValues = MetricValuesToDictionary(validationMetrics);
4646

47-
this.PrimaryMetricValue = this.MetricValues[this.primaryMetricName];
47+
this.PrimaryMetricValue = this.MetricValues[this._primaryMetricName];
4848
}
4949

5050
public TaskAgnosticIterationResult(RunDetail<RegressionMetrics> runDetail, string primaryMetricName = "RSquared")

test/Microsoft.ML.Benchmarks.Tests/BenchmarksTest.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,31 @@ public void BenchmarksProjectIsNotBroken(Type type)
7373

7474
public class OutputLogger : AccumulationLogger
7575
{
76-
private readonly ITestOutputHelper testOutputHelper;
77-
private string currentLine = "";
76+
private readonly ITestOutputHelper _testOutputHelper;
77+
private string _currentLine = "";
7878

7979
public OutputLogger(ITestOutputHelper testOutputHelper)
8080
{
81-
this.testOutputHelper = testOutputHelper ?? throw new ArgumentNullException(nameof(testOutputHelper));
81+
this._testOutputHelper = testOutputHelper ?? throw new ArgumentNullException(nameof(testOutputHelper));
8282
}
8383

8484
public override void Write(LogKind logKind, string text)
8585
{
86-
currentLine += text;
86+
_currentLine += text;
8787
base.Write(logKind, text);
8888
}
8989

9090
public override void WriteLine()
9191
{
92-
testOutputHelper.WriteLine(currentLine);
93-
currentLine = "";
92+
_testOutputHelper.WriteLine(_currentLine);
93+
_currentLine = "";
9494
base.WriteLine();
9595
}
9696

9797
public override void WriteLine(LogKind logKind, string text)
9898
{
99-
testOutputHelper.WriteLine(currentLine + text);
100-
currentLine = "";
99+
_testOutputHelper.WriteLine(_currentLine + text);
100+
_currentLine = "";
101101
base.WriteLine(logKind, text);
102102
}
103103
}

test/Microsoft.ML.Benchmarks/FeaturizeTextBench.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@ namespace Microsoft.ML.Benchmarks
1616
[Config(typeof(TrainConfig))]
1717
public class FeaturizeTextBench
1818
{
19-
private MLContext mlContext;
20-
private IDataView dataset;
21-
private static int numColumns = 1000;
22-
private static int numRows = 300;
23-
private static int maxWordLength = 15;
19+
private MLContext _mlContext;
20+
private IDataView _dataset;
21+
private static int _numColumns = 1000;
22+
private static int _numRows = 300;
23+
private static int _maxWordLength = 15;
2424

2525
[GlobalSetup]
2626
public void SetupData()
2727
{
2828
Path.GetTempFileName();
29-
mlContext = new MLContext(seed: 1);
29+
_mlContext = new MLContext(seed: 1);
3030
var path = Path.GetTempFileName();
3131
Console.WriteLine($"Created dataset in temporary file:\n{path}\n");
3232
path = CreateRandomFile(path);
3333

3434
var columns = new List<TextLoader.Column>();
35-
for(int i = 0; i < numColumns; i++)
35+
for(int i = 0; i < _numColumns; i++)
3636
{
3737
columns.Add(new TextLoader.Column($"Column{i}", DataKind.String, i));
3838
}
3939

40-
var textLoader = mlContext.Data.CreateTextLoader(new TextLoader.Options()
40+
var textLoader = _mlContext.Data.CreateTextLoader(new TextLoader.Options()
4141
{
4242
Columns = columns.ToArray(),
4343
HasHeader = false,
4444
Separators = new char[] { ',' }
4545
});
4646

47-
dataset = textLoader.Load(path);
47+
_dataset = textLoader.Load(path);
4848
}
4949

5050
[Benchmark]
@@ -59,7 +59,7 @@ public ITransformer TrainFeaturizeText()
5959
var featurizers = new List<TextFeaturizingEstimator>();
6060
foreach (var textColumn in textColumns)
6161
{
62-
var featurizer = mlContext.Transforms.Text.FeaturizeText(textColumn, new TextFeaturizingEstimator.Options()
62+
var featurizer = _mlContext.Transforms.Text.FeaturizeText(textColumn, new TextFeaturizingEstimator.Options()
6363
{
6464
CharFeatureExtractor = null,
6565
WordFeatureExtractor = new WordBagEstimator.Options()
@@ -77,7 +77,7 @@ public ITransformer TrainFeaturizeText()
7777
pipeline = pipeline.Append(featurizer);
7878
}
7979

80-
var model = pipeline.Fit(dataset);
80+
var model = pipeline.Fit(_dataset);
8181

8282
// BENCHMARK OUTPUT
8383
// * Summary *
@@ -126,8 +126,8 @@ public static string CreateRandomFile(string path)
126126

127127
using (StreamWriter file = new StreamWriter(path))
128128
{
129-
for(int i = 0; i < numRows; i++)
130-
file.WriteLine(CreateRandomLine(numColumns, random));
129+
for(int i = 0; i < _numRows; i++)
130+
file.WriteLine(CreateRandomLine(_numColumns, random));
131131
}
132132
return path;
133133
}
@@ -155,7 +155,7 @@ public static string CreateRandomColumn(Random random, int numwords)
155155

156156
for(int i = 0; i < numwords; i++)
157157
{
158-
wordLength = random.Next(1, maxWordLength);
158+
wordLength = random.Next(1, _maxWordLength);
159159
for(int j = 0; j < wordLength; j++)
160160
columnSB.Append(characters[random.Next(characters.Length)]);
161161

test/Microsoft.ML.Benchmarks/Harness/ProjectGenerator.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ namespace Microsoft.ML.Benchmarks.Harness
2525
/// </summary>
2626
public class ProjectGenerator : CsProjGenerator
2727
{
28-
private readonly string runtimeIdentifier = string.Empty;
28+
private readonly string _runtimeIdentifier = string.Empty;
2929

3030
public ProjectGenerator(string targetFrameworkMoniker) : base(targetFrameworkMoniker, null, null, null)
3131
{
3232
#if NETFRAMEWORK
33-
runtimeIdentifier = "win-x64";
33+
_runtimeIdentifier = "win-x64";
3434
#endif
3535
}
3636

@@ -41,7 +41,7 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
4141
<OutputType>Exe</OutputType>
4242
<OutputPath>bin\{buildPartition.BuildConfiguration}</OutputPath>
4343
<TargetFramework>{TargetFrameworkMoniker}</TargetFramework>
44-
<RuntimeIdentifier>{runtimeIdentifier}</RuntimeIdentifier>
44+
<RuntimeIdentifier>{_runtimeIdentifier}</RuntimeIdentifier>
4545
<AssemblyName>{artifactsPaths.ProgramName}</AssemblyName>
4646
<AssemblyTitle>{artifactsPaths.ProgramName}</AssemblyTitle>
4747
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -61,7 +61,7 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
6161

6262
// This overrides the .exe path to also involve the runtimeIdentifier for .NET Framework
6363
protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
64-
=> Path.Combine(buildArtifactsDirectoryPath, "bin", configuration, TargetFrameworkMoniker, runtimeIdentifier);
64+
=> Path.Combine(buildArtifactsDirectoryPath, "bin", configuration, TargetFrameworkMoniker, _runtimeIdentifier);
6565

6666
private string GenerateNativeReferences(BuildPartition buildPartition, ILogger logger)
6767
{

0 commit comments

Comments
 (0)