1515using Xunit ;
1616using Microsoft . ML . TestFramework . Attributes ;
1717using System . Threading ;
18+ using Microsoft . ML . Data ;
1819
1920namespace Microsoft . Data . Analysis . Tests
2021{
@@ -273,7 +274,7 @@ void ReducedRowsTest(DataFrame reducedRows)
273274 [ Theory ]
274275 [ InlineData ( false ) ]
275276 [ InlineData ( true ) ]
276- public void TestReadCsvNoHeader ( bool useQuotes )
277+ public void TestLoadCsvNoHeader ( bool useQuotes )
277278 {
278279 string CMT = useQuotes ? @"""C,MT""" : "CMT" ;
279280 string verifyCMT = useQuotes ? "C,MT" : "CMT" ;
@@ -349,7 +350,7 @@ void VerifyDataFrameWithNamedColumnsAndDataTypes(DataFrame df, bool verifyColumn
349350 [ InlineData ( false , 0 ) ]
350351 [ InlineData ( true , 10 ) ]
351352 [ InlineData ( false , 10 ) ]
352- public void TestReadCsvWithTypesAndGuessRows ( bool header , int guessRows )
353+ public void TestLoadCsvWithTypesAndGuessRows ( bool header , int guessRows )
353354 {
354355 /* Tests this matrix
355356 *
@@ -472,7 +473,7 @@ void Verify(DataFrame df)
472473 }
473474
474475 [ Fact ]
475- public void TestReadCsvWithTypesDateTime ( )
476+ public void TestLoadCsvWithTypesDateTime ( )
476477 {
477478 string data = @"vendor_id,rate_code,passenger_count,trip_time_in_secs,trip_distance,payment_type,fare_amount,date
478479CMT,1,1,1271,3.8,CRD,17.5,1-june-2020
@@ -549,7 +550,7 @@ void Verify(DataFrame df, bool verifyDataTypes)
549550 }
550551
551552 [ Fact ]
552- public void TestReadCsvWithPipeSeparator ( )
553+ public void TestLoadCsvWithPipeSeparator ( )
553554 {
554555 string data = @"vendor_id|rate_code|passenger_count|trip_time_in_secs|trip_distance|payment_type|fare_amount
555556CMT|1|1|1271|3.8|CRD|17.5
@@ -588,7 +589,7 @@ void Verify(DataFrame df)
588589 }
589590
590591 [ Fact ]
591- public void TestReadCsvWithSemicolonSeparator ( )
592+ public void TestLoadCsvWithSemicolonSeparator ( )
592593 {
593594 string data = @"vendor_id;rate_code;passenger_count;trip_time_in_secs;trip_distance;payment_type;fare_amount
594595CMT;1;1;1271;3.8;CRD;17.5
@@ -627,7 +628,7 @@ void Verify(DataFrame df)
627628 }
628629
629630 [ Fact ]
630- public void TestReadCsvWithExtraColumnInHeader ( )
631+ public void TestLoadCsvWithExtraColumnInHeader ( )
631632 {
632633 string data = @"vendor_id,rate_code,passenger_count,trip_time_in_secs,trip_distance,payment_type,fare_amount,extra
633634CMT,1,1,1271,3.8,CRD,17.5
@@ -656,7 +657,7 @@ void Verify(DataFrame df)
656657 }
657658
658659 [ Fact ]
659- public void TestReadCsvWithMultipleEmptyColumnNameInHeaderWithoutGivenColumn ( )
660+ public void TestLoadCsvWithMultipleEmptyColumnNameInHeaderWithoutGivenColumn ( )
660661 {
661662 string data = @"vendor_id,rate_code,passenger_count,trip_time_in_secs,,,,
662663CMT,1,1,1271,3.8,CRD,17.5,0
@@ -671,7 +672,7 @@ public void TestReadCsvWithMultipleEmptyColumnNameInHeaderWithoutGivenColumn()
671672 }
672673
673674 [ Fact ]
674- public void TestReadCsvWithMultipleEmptyColumnNameInHeaderWithGivenColumn ( )
675+ public void TestLoadCsvWithMultipleEmptyColumnNameInHeaderWithGivenColumn ( )
675676 {
676677 string data = @"vendor_id,rate_code,passenger_count,trip_time_in_secs,,,,
677678CMT,1,1,1271,3.8,CRD,17.5,0
@@ -713,7 +714,7 @@ public void TestLoadCsvWithAddIndexColumn()
713714 }
714715
715716 [ Fact ]
716- public void TestReadCsvWithExtraColumnInRow ( )
717+ public void TestLoadCsvWithExtraColumnInRow ( )
717718 {
718719 string data = @"vendor_id,rate_code,passenger_count,trip_time_in_secs,trip_distance,payment_type,fare_amount
719720CMT,1,1,1271,3.8,CRD,17.5,0
@@ -726,7 +727,7 @@ public void TestReadCsvWithExtraColumnInRow()
726727 }
727728
728729 [ Fact ]
729- public void TestReadCsvWithLessColumnsInRow ( )
730+ public void TestLoadCsvWithLessColumnsInRow ( )
730731 {
731732 string data = @"vendor_id,rate_code,passenger_count,trip_time_in_secs,trip_distance,payment_type,fare_amount
732733CMT,1,1,1271,3.8,CRD
@@ -755,7 +756,7 @@ void Verify(DataFrame df)
755756 }
756757
757758 [ Fact ]
758- public void TestReadCsvWithAllNulls ( )
759+ public void TestLoadCsvWithAllNulls ( )
759760 {
760761 string data = @"vendor_id,rate_code,passenger_count,trip_time_in_secs
761762null,null,null,null
@@ -798,7 +799,7 @@ void Verify(DataFrame df)
798799 }
799800
800801 [ Fact ]
801- public void TestReadCsvWithNullsAndDataTypes ( )
802+ public void TestLoadCsvWithNullsAndDataTypes ( )
802803 {
803804 string data = @"vendor_id,rate_code,passenger_count,trip_time_in_secs
804805null,1,1,1271
@@ -860,7 +861,7 @@ void Verify(DataFrame df)
860861 }
861862
862863 [ Fact ]
863- public void TestReadCsvWithNulls ( )
864+ public void TestLoadCsvWithNulls ( )
864865 {
865866 string data = @"vendor_id,rate_code,passenger_count,trip_time_in_secs
866867null,1,1,1271
@@ -922,7 +923,36 @@ void Verify(DataFrame df)
922923 }
923924
924925 [ Fact ]
925- public void TestWriteCsvWithHeader ( )
926+ public void TestSaveCsvVBufferColumn ( )
927+ {
928+ var vBuffers = new [ ]
929+ {
930+ new VBuffer < int > ( 3 , new int [ ] { 1 , 2 , 3 } ) ,
931+ new VBuffer < int > ( 3 , new int [ ] { 2 , 3 , 4 } ) ,
932+ new VBuffer < int > ( 3 , new int [ ] { 3 , 4 , 5 } ) ,
933+ } ;
934+
935+ var vBufferColumn = new VBufferDataFrameColumn < int > ( "VBuffer" , vBuffers ) ;
936+ DataFrame dataFrame = new DataFrame ( vBufferColumn ) ;
937+
938+ using MemoryStream csvStream = new MemoryStream ( ) ;
939+
940+ DataFrame . SaveCsv ( dataFrame , csvStream ) ;
941+
942+ csvStream . Seek ( 0 , SeekOrigin . Begin ) ;
943+ DataFrame readIn = DataFrame . LoadCsv ( csvStream ) ;
944+
945+ Assert . Equal ( dataFrame . Rows . Count , readIn . Rows . Count ) ;
946+ Assert . Equal ( dataFrame . Columns . Count , readIn . Columns . Count ) ;
947+
948+ Assert . Equal ( typeof ( string ) , readIn . Columns [ 0 ] . DataType ) ;
949+ Assert . Equal ( "(1 2 3)" , readIn [ 0 , 0 ] ) ;
950+ Assert . Equal ( "(2 3 4)" , readIn [ 1 , 0 ] ) ;
951+ Assert . Equal ( "(3 4 5)" , readIn [ 2 , 0 ] ) ;
952+ }
953+
954+ [ Fact ]
955+ public void TestSaveCsvWithHeader ( )
926956 {
927957 using MemoryStream csvStream = new MemoryStream ( ) ;
928958 DataFrame dataFrame = DataFrameTests . MakeDataFrameWithAllColumnTypes ( 10 , true ) ;
0 commit comments