-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Extension on IDataReader<IMultiStreamSource>, and DataReader<IMultiStreamSource, TShape> to read from one or several file paths, rather than requiring constructing an IMultiStreamSource #1281
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
Changes from all commits
fd2a7f2
cd91553
0318a46
69e9298
0425636
71b28dd
5d3a940
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,5 +256,17 @@ public Column Create() | |
} | ||
} | ||
} | ||
} | ||
|
||
public static class LocalPathReader | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think it belongs to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I just added an instance method to In reply to: 226082986 [](ancestors = 226082986,226074992) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
public static IDataView Read(this IDataReader<IMultiStreamSource> reader, params string[] path) | ||
{ | ||
return reader.Read(new MultiFileSource(path)); | ||
} | ||
|
||
public static DataView<TShape> Read<TShape>(this DataReader<IMultiStreamSource, TShape> reader, params string[] path) | ||
{ | ||
return reader.Read(new MultiFileSource(path)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.ML.Runtime.Data; | ||
using System; | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace Microsoft.ML.Runtime.RunTests | ||
{ | ||
public sealed class FileSource | ||
{ | ||
|
||
[Fact] | ||
public void MultiFileSourceUnitTest() | ||
{ | ||
var fileSource = new MultiFileSource("adult.txt"); | ||
Assert.True(fileSource.Count == 1); | ||
|
||
fileSource = new MultiFileSource("adult.train", "adult.test"); | ||
Assert.True(fileSource.Count == 2, $"Error passing multiple paths to {nameof(MultiFileSource)}"); | ||
|
||
//creating a directory with three files for the tests | ||
var dirName = Directory.CreateDirectory("MultiFileSourceUnitTest").FullName; | ||
|
||
var file1 = Path.Combine(dirName, "a.txt"); | ||
var file2 = Path.Combine(dirName, "b.txt"); | ||
|
||
File.WriteAllText(file1, "Unit Test"); | ||
File.WriteAllText(file2, "Unit Test"); | ||
|
||
fileSource = new MultiFileSource($"{file1}+{file2}"); | ||
Assert.True(fileSource.Count == 2, $"Error passing concatenated paths to {nameof(MultiFileSource)}"); | ||
|
||
fileSource = new MultiFileSource(Path.Combine(dirName, "...")); | ||
Assert.True(fileSource.Count == 2, $"Error passing concatenated paths to {nameof(MultiFileSource)}"); | ||
|
||
Assert.Throws<InvalidOperationException>(() => new MultiFileSource($"{file1}+{file2}", "adult.test")); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to put this in xml doc comments. #Resolved