Skip to content

Commit a56caee

Browse files
authored
Lockdown Microsoft.ML.Data Dataview folder. (#2608)
* Lockdown Microsoft.ML.Data Dataview folder. * PR feedback.
1 parent f9d5ec2 commit a56caee

File tree

10 files changed

+37
-40
lines changed

10 files changed

+37
-40
lines changed

src/Microsoft.ML.Data/DataView/AppendRowsDataView.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ namespace Microsoft.ML.Data
2727
///
2828
/// An AppendRowsDataView instance is shuffleable iff all of its sources are shuffleable and their row counts are known.
2929
/// </summary>
30-
public sealed class AppendRowsDataView : IDataView
30+
[BestFriend]
31+
internal sealed class AppendRowsDataView : IDataView
3132
{
3233
public const string RegistrationName = "AppendRowsDataView";
3334

src/Microsoft.ML.Data/DataView/CompositeRowToRowMapper.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace Microsoft.ML.Data
1111
/// <summary>
1212
/// A row-to-row mapper that is the result of a chained application of multiple mappers.
1313
/// </summary>
14-
public sealed class CompositeRowToRowMapper : IRowToRowMapper
14+
[BestFriend]
15+
internal sealed class CompositeRowToRowMapper : IRowToRowMapper
1516
{
1617
[BestFriend]
1718
internal IRowToRowMapper[] InnerMappers { get; }

src/Microsoft.ML.Data/DataView/EmptyDataView.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ namespace Microsoft.ML.Data
1212
/// <summary>
1313
/// This implements a data view that has a schema, but no rows.
1414
/// </summary>
15-
public sealed class EmptyDataView : IDataView
15+
[BestFriend]
16+
internal sealed class EmptyDataView : IDataView
1617
{
1718
private readonly IHost _host;
1819

src/Microsoft.ML.Data/DataView/LambdaFilter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.ML.Data
1616
/// This applies the user provided RefPredicate to a column and drops rows that map to false. It automatically
1717
/// injects a standard conversion from the actual type of the source column to typeSrc (if needed).
1818
/// </summary>
19-
public static class LambdaFilter
19+
internal static class LambdaFilter
2020
{
2121
public static IDataView Create<TSrc>(IHostEnvironment env, string name, IDataView input,
2222
string src, DataViewType typeSrc, InPredicate<TSrc> predicate)

src/Microsoft.ML.Data/DataView/OpaqueDataView.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ namespace Microsoft.ML.Data
1212
/// Opaque IDataView implementation to provide a barrier for data pipe optimizations.
1313
/// Used in cross validatation to generate the train/test pipelines for each fold.
1414
/// </summary>
15-
public sealed class OpaqueDataView : IDataView
15+
[BestFriend]
16+
internal sealed class OpaqueDataView : IDataView
1617
{
1718
private readonly IDataView _source;
1819
public bool CanShuffle => _source.CanShuffle;

src/Microsoft.ML.Data/DataView/SimpleRow.cs

-13
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,4 @@ public override bool IsColumnActive(int col)
6969
return _getters[col] != null;
7070
}
7171
}
72-
73-
public static class SimpleSchemaUtils
74-
{
75-
public static DataViewSchema Create(IExceptionContext ectx, params KeyValuePair<string, DataViewType>[] columns)
76-
{
77-
Contracts.CheckValueOrNull(ectx);
78-
ectx.CheckValue(columns, nameof(columns));
79-
80-
var builder = new SchemaBuilder();
81-
builder.AddColumns(columns.Select(kvp => new DataViewSchema.DetachedColumn(kvp.Key, kvp.Value)));
82-
return builder.GetSchema();
83-
}
84-
}
8572
}

src/Microsoft.ML.Data/DataView/TypedCursor.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ internal interface IRowReadableAs<TRow> : IDisposable
3232
/// It can populate the user-supplied object's fields with the values of the current row.
3333
/// </summary>
3434
/// <typeparam name="TRow">The user-defined type that is being populated while cursoring.</typeparam>
35-
public abstract class RowCursor<TRow> : DataViewRowCursor, IRowReadableAs<TRow>
35+
[BestFriend]
36+
internal abstract class RowCursor<TRow> : DataViewRowCursor, IRowReadableAs<TRow>
3637
where TRow : class
3738
{
3839
public abstract void FillValues(TRow row);
@@ -42,7 +43,8 @@ public abstract class RowCursor<TRow> : DataViewRowCursor, IRowReadableAs<TRow>
4243
/// This interface allows to create strongly typed cursors over a <see cref="IDataView"/>.
4344
/// </summary>
4445
/// <typeparam name="TRow">The user-defined type that is being populated while cursoring.</typeparam>
45-
public interface ICursorable<TRow>
46+
[BestFriend]
47+
internal interface ICursorable<TRow>
4648
where TRow : class
4749
{
4850
/// <summary>

src/Microsoft.ML.Data/DataView/ZipDataView.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace Microsoft.ML.Data
1414
/// This is a data view that is a 'zip' of several data views.
1515
/// The length of the zipped data view is equal to the shortest of the lengths of the components.
1616
/// </summary>
17-
public sealed class ZipDataView : IDataView
17+
[BestFriend]
18+
internal sealed class ZipDataView : IDataView
1819
{
1920
// REVIEW: there are other potential 'zip modes' that can be implemented:
2021
// * 'zip longest', iterate until all sources finish, and return the 'sensible missing values' for sources that ended

src/Microsoft.ML.Data/Evaluators/BinaryClassifierEvaluator.cs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,9 @@ private static IDataView ExtractWarnings(IHost host, Dictionary<string, IDataVie
15591559
IDataView warnings;
15601560
if (!metrics.TryGetValue(MetricKinds.Warnings, out warnings))
15611561
{
1562-
warnings = new EmptyDataView(host, SimpleSchemaUtils.Create(host,
1563-
new KeyValuePair<string, DataViewType>(MetricKinds.ColumnNames.WarningText, TextDataViewType.Instance)));
1562+
var schemaBuilder = new SchemaBuilder();
1563+
schemaBuilder.AddColumn(MetricKinds.ColumnNames.WarningText, TextDataViewType.Instance);
1564+
warnings = new EmptyDataView(host, schemaBuilder.GetSchema());
15641565
}
15651566

15661567
return warnings;
@@ -1571,11 +1572,11 @@ private static IDataView ExtractOverallMetrics(IHost host, Dictionary<string, ID
15711572
IDataView overallMetrics;
15721573
if (!metrics.TryGetValue(MetricKinds.OverallMetrics, out overallMetrics))
15731574
{
1574-
overallMetrics = new EmptyDataView(host,
1575-
SimpleSchemaUtils.Create(host,
1576-
evaluator.GetOverallMetricColumns()
1577-
.Select(mc => new KeyValuePair<string, DataViewType>(mc.LoadName, NumberDataViewType.Double))
1578-
.ToArray()));
1575+
var schemaBuilder = new SchemaBuilder();
1576+
foreach (var mc in evaluator.GetOverallMetricColumns())
1577+
schemaBuilder.AddColumn(mc.LoadName, NumberDataViewType.Double);
1578+
1579+
overallMetrics = new EmptyDataView(host, schemaBuilder.GetSchema());
15791580
}
15801581

15811582
return overallMetrics;
@@ -1586,8 +1587,9 @@ private static IDataView ExtractConfusionMatrix(IHost host, Dictionary<string, I
15861587
IDataView confusionMatrix;
15871588
if (!metrics.TryGetValue(MetricKinds.ConfusionMatrix, out confusionMatrix))
15881589
{
1589-
confusionMatrix = new EmptyDataView(host,
1590-
SimpleSchemaUtils.Create(host, new KeyValuePair<string, DataViewType>(MetricKinds.ColumnNames.Count, NumberDataViewType.Double)));
1590+
var schemaBuilder = new SchemaBuilder();
1591+
schemaBuilder.AddColumn(MetricKinds.ColumnNames.Count, NumberDataViewType.Double);
1592+
confusionMatrix = new EmptyDataView(host, schemaBuilder.GetSchema());
15911593
}
15921594

15931595
return confusionMatrix;

test/Microsoft.ML.StaticPipelineTesting/StaticPipeTests.cs

+11-10
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ private static KeyValuePair<string, DataViewType> P(string name, DataViewType ty
207207
public void AssertStaticSimple()
208208
{
209209
var env = new MLContext(0);
210-
var schema = SimpleSchemaUtils.Create(env,
211-
P("hello", TextDataViewType.Instance),
212-
P("my", new VectorType(NumberDataViewType.Int64, 5)),
213-
P("friend", new KeyType(typeof(uint), 3)));
214-
var view = new EmptyDataView(env, schema);
210+
var schemaBuilder = new SchemaBuilder();
211+
schemaBuilder.AddColumn("hello", TextDataViewType.Instance);
212+
schemaBuilder.AddColumn("my", new VectorType(NumberDataViewType.Int64, 5));
213+
schemaBuilder.AddColumn("friend", new KeyType(typeof(uint), 3));
214+
var view = new EmptyDataView(env, schemaBuilder.GetSchema());
215215

216216
view.AssertStatic(env, c => new
217217
{
@@ -231,11 +231,12 @@ public void AssertStaticSimple()
231231
public void AssertStaticSimpleFailure()
232232
{
233233
var env = new MLContext(0);
234-
var schema = SimpleSchemaUtils.Create(env,
235-
P("hello", TextDataViewType.Instance),
236-
P("my", new VectorType(NumberDataViewType.Int64, 5)),
237-
P("friend", new KeyType(typeof(uint), 3)));
238-
var view = new EmptyDataView(env, schema);
234+
var schemaBuilder = new SchemaBuilder();
235+
schemaBuilder.AddColumn("hello", TextDataViewType.Instance);
236+
schemaBuilder.AddColumn("my", new VectorType(NumberDataViewType.Int64, 5));
237+
schemaBuilder.AddColumn("friend", new KeyType(typeof(uint), 3));
238+
239+
var view = new EmptyDataView(env, schemaBuilder.GetSchema());
239240

240241
Assert.ThrowsAny<Exception>(() =>
241242
view.AssertStatic(env, c => new

0 commit comments

Comments
 (0)