Esempio n. 1
0
            public DataFrame(IEnumerable <TColumn> columnHeaders, IEnumerable <ImmutableList <double> > dataColumns)
            {
                ColumnHeaders = ImmutableList.ValueOf(columnHeaders);
                DataColumns   = ImmutableList.ValueOf(dataColumns);
                if (ColumnHeaders.Count == 0)
                {
                    throw new ArgumentException(nameof(columnHeaders));
                }
                if (ColumnHeaders.Count != DataColumns.Count)
                {
                    throw new ArgumentException(@"Wrong number of data columns", nameof(dataColumns));
                }
                if (DataColumns.Select(col => col.Count).Distinct().Count() > 1)
                {
                    throw new ArgumentException(@"All data columns must have the same number of rows", nameof(dataColumns));
                }

                for (int iColumn = 0; iColumn < DataColumns.Count; iColumn++)
                {
                    var col = DataColumns[iColumn];
                    for (int iRow = 0; iRow < col.Count; iRow++)
                    {
                        var value = col[iRow];
                        if (double.IsNaN(value) || double.IsInfinity(value))
                        {
                            throw new ArgumentException(string.Format(@"{0} found at row {1} column {2}", value, iRow, iColumn), nameof(dataColumns));
                        }
                    }
                }
            }
Esempio n. 2
0
 public DataFrame ReorderRows(IList <int> newOrdering)
 {
     return(new DataFrame(ColumnHeaders, DataColumns.Select(col => ImmutableList.ValueOf(Reorder(col, newOrdering)))));
 }