File tree Expand file tree Collapse file tree 3 files changed +13
-11
lines changed
src/Microsoft.Data.Analysis
tests/Microsoft.Data.Analysis.Tests Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -33,13 +33,14 @@ public partial class DataFrame
3333 {
3434 private readonly DataFrameColumnCollection _columnCollection ;
3535 private readonly DataFrameRowCollection _rowCollection ;
36- public DataFrame ( )
36+
37+ public DataFrame ( IEnumerable < DataFrameColumn > columns )
3738 {
38- _columnCollection = new DataFrameColumnCollection ( OnColumnsChanged ) ;
39+ _columnCollection = new DataFrameColumnCollection ( columns , OnColumnsChanged ) ;
3940 _rowCollection = new DataFrameRowCollection ( this ) ;
4041 }
4142
42- public DataFrame ( IList < DataFrameColumn > columns )
43+ public DataFrame ( params DataFrameColumn [ ] columns )
4344 {
4445 _columnCollection = new DataFrameColumnCollection ( columns , OnColumnsChanged ) ;
4546 _rowCollection = new DataFrameRowCollection ( this ) ;
Original file line number Diff line number Diff line change @@ -21,18 +21,13 @@ public class DataFrameColumnCollection : Collection<DataFrameColumn>
2121
2222 internal long RowCount { get ; set ; }
2323
24- internal DataFrameColumnCollection ( Action columnsChanged ) : base ( )
25- {
26- ColumnsChanged = columnsChanged ;
27- }
28-
29- internal DataFrameColumnCollection ( IList < DataFrameColumn > columns , Action columnsChanged ) : base ( )
24+ internal DataFrameColumnCollection ( IEnumerable < DataFrameColumn > columns , Action columnsChanged ) : base ( )
3025 {
3126 columns = columns ?? throw new ArgumentNullException ( nameof ( columns ) ) ;
3227 ColumnsChanged = columnsChanged ;
33- for ( int i = 0 ; i < columns . Count ; i ++ )
28+ foreach ( DataFrameColumn column in columns )
3429 {
35- Add ( columns [ i ] ) ;
30+ Add ( column ) ;
3631 }
3732 }
3833
Original file line number Diff line number Diff line change @@ -235,6 +235,12 @@ public void ColumnAndTableCreationTest()
235235 dataFrame . Columns . RemoveAt ( 1 ) ;
236236 Assert . Single ( dataFrame . Columns ) ;
237237 Assert . True ( ReferenceEquals ( intColumn , dataFrame . Columns [ 0 ] ) ) ;
238+
239+ // Test the params constructor
240+ DataFrame dataFrame1 = new DataFrame ( intColumn , floatColumn ) ;
241+ Assert . Equal ( 2 , dataFrame1 . Columns . Count ) ;
242+ Assert . Equal ( intColumn , dataFrame1 . Columns [ 0 ] ) ;
243+ Assert . Equal ( floatColumn , dataFrame1 . Columns [ 1 ] ) ;
238244 }
239245
240246 [ Fact ]
You can’t perform that action at this time.
0 commit comments