- Timestamp:
- 07/07/17 16:44:47 (7 years ago)
- Location:
- stable
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14284-14286,14288,14296,14298,14408
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.Instances.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis merged: 14285,14296,14408
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.Instances.DataAnalysis.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views merged: 14285-14286,14298
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/DataAnalysisImportTypeDialog.cs
r14186 r15170 158 158 } 159 159 catch (Exception ex) { 160 if (ex is IOException || ex is InvalidOperationException || ex is ArgumentException || ex is TableFileParser.DataFormatException) {160 if (ex is IOException || ex is InvalidOperationException || ex is ArgumentException) { 161 161 OkButton.Enabled = false; 162 162 ErrorTextBox.Text = ex.Message; -
stable/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/RegressionInstanceProviderView.cs
r14186 r15170 52 52 53 53 try { 54 var progress = mainForm.AddOperationProgressToContent(activeView.Content, "Loading problem instance."); 54 var progress = mainForm.AddOperationProgressToContent(activeView.Content, 55 "Loading problem instance."); 55 56 56 Content.ProgressChanged += (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; }; 57 Content.ProgressChanged += 58 (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; }; 57 59 58 instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType, importTypeDialog.CSVFormat); 59 } catch (IOException ex) { 60 instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType, 61 importTypeDialog.CSVFormat); 62 } catch (Exception ex) { 60 63 ErrorWhileParsing(ex); 64 return; 65 } finally { 61 66 mainForm.RemoveOperationProgressFromContent(activeView.Content); 62 return;63 67 } 68 64 69 try { 65 70 GenericConsumer.Load(instance); 66 } catch ( IOException ex) {71 } catch (Exception ex) { 67 72 ErrorWhileLoading(ex, importTypeDialog.Path); 68 73 } finally { -
stable/HeuristicLab.Problems.Instances.DataAnalysis/3.3/TableFileParser.cs
r14186 r15170 28 28 using System.IO; 29 29 using System.Linq; 30 using System.Runtime.Serialization;31 30 using System.Text; 32 31 … … 198 197 /// <param name="columnNamesInFirstLine"></param> 199 198 public void Parse(Stream stream, NumberFormatInfo numberFormat, DateTimeFormatInfo dateTimeFormatInfo, char separator, bool columnNamesInFirstLine, int lineLimit = -1) { 200 using (StreamReader reader = new StreamReader(stream, Encoding)) { 199 if (lineLimit > 0) estimatedNumberOfLines = lineLimit; 200 201 using (var reader = new StreamReader(stream)) { 201 202 tokenizer = new Tokenizer(reader, numberFormat, dateTimeFormatInfo, separator); 203 var strValues = new List<List<string>>(); 202 204 values = new List<IList>(); 203 if (lineLimit > 0) estimatedNumberOfLines = lineLimit; 204 205 if (columnNamesInFirstLine) { 206 ParseVariableNames(); 207 if (!tokenizer.HasNext()) 208 Error( 209 "Couldn't parse data values. Probably because of incorrect number format (the parser expects english number format with a '.' as decimal separator).", 210 "", tokenizer.CurrentLineNumber); 211 } 212 213 214 // read values... start in first row 205 Prepare(columnNamesInFirstLine, strValues); 206 215 207 int nLinesParsed = 0; 216 208 int colIdx = 0; 217 int numValuesInFirstRow = columnNamesInFirstLine ? variableNames.Count : -1; // number of variables or inizialize based on first row of values (-1)218 209 while (tokenizer.HasNext() && (lineLimit < 0 || nLinesParsed < lineLimit)) { 219 210 if (tokenizer.PeekType() == TokenTypeEnum.NewLine) { … … 221 212 222 213 // all rows have to have the same number of values 223 // the first row defines how many samples are needed224 if ( numValuesInFirstRow < 0) numValuesInFirstRow = values.Count; // set to number of colums in the first row225 else if (colIdx > 0 && numValuesInFirstRow != colIdx) {// read at least one value in the row (support for skipping empty lines)226 Error("The first row of the dataset has " + numValuesInFirstRow+ " columns." + Environment.NewLine +214 // the first row defines how many elements are needed 215 if (colIdx > 0 && values.Count != colIdx) { 216 // read at least one value in the row (support for skipping empty lines) 217 Error("The first row of the dataset has " + values.Count + " columns." + Environment.NewLine + 227 218 "Line " + tokenizer.CurrentLineNumber + " has " + colIdx + " columns.", "", 228 219 tokenizer.CurrentLineNumber); 229 220 } 230 221 OnReport(tokenizer.BytesRead); … … 234 225 } else { 235 226 // read one value 236 TokenTypeEnum type; string strVal; double dblVal; DateTime dateTimeVal; 227 TokenTypeEnum type; 228 string strVal; 229 double dblVal; 230 DateTime dateTimeVal; 237 231 tokenizer.Next(out type, out strVal, out dblVal, out dateTimeVal); 238 232 239 // initialize columns on the first row (fixing data types as presented in the first row...) 240 if (nLinesParsed == 0) { 241 values.Add(CreateList(type, estimatedNumberOfLines)); 242 } else if (colIdx == values.Count) { 243 Error("The first row of the dataset has " + numValuesInFirstRow + " columns." + Environment.NewLine + 233 if (colIdx == values.Count) { 234 Error("The first row of the dataset has " + values.Count + " columns." + Environment.NewLine + 244 235 "Line " + tokenizer.CurrentLineNumber + " has more columns.", "", 245 236 tokenizer.CurrentLineNumber); 246 237 } 247 238 if (!IsColumnTypeCompatible(values[colIdx], type)) { 248 values[colIdx] = ConvertToStringColumn(values[colIdx]);239 values[colIdx] = strValues[colIdx]; 249 240 } 241 250 242 // add the value to the column 251 AddValue(type, values[colIdx++], strVal, dblVal, dateTimeVal); 243 AddValue(type, values[colIdx], strVal, dblVal, dateTimeVal); 244 if (!(values[colIdx] is List<string>)) { // optimization: don't store the string values in another list if the column is list<string> 245 strValues[colIdx].Add(strVal); 246 } 247 colIdx++; 252 248 } 253 249 } 254 255 if (!values.Any() || values.First().Count == 0) 256 Error("Couldn't parse data values. Probably because of incorrect number format " +257 "(the parser expects english number format with a '.' as decimal separator).", "", tokenizer.CurrentLineNumber);258 }250 } 251 252 if (!values.Any() || values.First().Count == 0) 253 Error("Couldn't parse data values. Probably because of incorrect number format " + 254 "(the parser expects english number format with a '.' as decimal separator).", "", tokenizer.CurrentLineNumber); 259 255 260 256 this.rows = values.First().Count; … … 277 273 // for large files we created a lot of memory pressure, cannot hurt to run GC.Collect here (TableFileParser is called seldomly on user interaction) 278 274 GC.Collect(2, GCCollectionMode.Forced); 275 } 276 277 private void Prepare(bool columnNamesInFirstLine, List<List<string>> strValues) { 278 if (columnNamesInFirstLine) { 279 ParseVariableNames(); 280 if (!tokenizer.HasNext()) 281 Error( 282 "Couldn't parse data values. Probably because of incorrect number format (the parser expects english number format with a '.' as decimal separator).", 283 "", tokenizer.CurrentLineNumber); 284 } 285 // read first line to determine types and allocate specific lists 286 // read values... start in first row 287 int colIdx = 0; 288 while (tokenizer.PeekType() != TokenTypeEnum.NewLine) { 289 // read one value 290 TokenTypeEnum type; string strVal; double dblVal; DateTime dateTimeVal; 291 tokenizer.Next(out type, out strVal, out dblVal, out dateTimeVal); 292 293 // initialize column 294 values.Add(CreateList(type, estimatedNumberOfLines)); 295 if (type == TokenTypeEnum.String) 296 strValues.Add(new List<string>(0)); // optimization: don't store the string values in another list if the column is list<string> 297 else 298 strValues.Add(new List<string>(estimatedNumberOfLines)); 299 300 AddValue(type, values[colIdx], strVal, dblVal, dateTimeVal); 301 if (type != TokenTypeEnum.String) 302 strValues[colIdx].Add(strVal); 303 colIdx++; 304 } 305 tokenizer.Skip(); // skip newline 279 306 } 280 307 … … 530 557 type = TokenTypeEnum.Double; 531 558 doubleVals[i] = doubleVal; 532 } else if (DateTime.TryParse(tok, dateTimeFormatInfo, DateTimeStyles.None, out dateTimeValue)) { 559 } else if (DateTime.TryParse(tok, dateTimeFormatInfo, DateTimeStyles.NoCurrentDateDefault, out dateTimeValue) 560 && (dateTimeValue.Year > 1 || dateTimeValue.Month > 1 || dateTimeValue.Day > 1)// if no date is given it is returned as 1.1.0001 -> don't allow this 561 ) { 533 562 type = TokenTypeEnum.DateTime; 534 563 dateTimeVals[i] = dateTimeValue; … … 606 635 607 636 private void Error(string message, string token, int lineNumber) { 608 throw new DataFormatException("Error while parsing.\n" + message, token, lineNumber);637 throw new IOException(string.Format("Error while parsing. {0} (token: {1} lineNumber: {2}).", message, token, lineNumber)); 609 638 } 610 639 #endregion 611 612 [Serializable]613 public class DataFormatException : Exception {614 private int line;615 public int Line {616 get { return line; }617 }618 private string token;619 public string Token {620 get { return token; }621 }622 public DataFormatException(string message, string token, int line)623 : base(message + "\nToken: " + token + " (line: " + line + ")") {624 this.token = token;625 this.line = line;626 }627 628 public DataFormatException(SerializationInfo info, StreamingContext context) : base(info, context) { }629 }630 640 } 631 641 } -
stable/HeuristicLab.Tests
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Tests merged: 14284,14288
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Tests/HeuristicLab.Problems.Instances.DataAnalysis-3.3/TableFileParserTest.cs
r14186 r15170 24 24 using System.Globalization; 25 25 using System.IO; 26 using System.Text; 26 27 using Microsoft.VisualStudio.TestTools.UnitTesting; 27 28 … … 47 48 Assert.AreEqual(4, parser.Columns); 48 49 Assert.AreEqual(parser.Values[3][0], 3.14); 49 } finally { 50 } 51 finally { 50 52 File.Delete(tempFileName); 51 53 } … … 71 73 Assert.AreEqual(4, parser.Columns); 72 74 Assert.AreEqual(parser.Values[3][0], 3.14); 73 } finally { 75 } 76 finally { 74 77 File.Delete(tempFileName); 75 78 } … … 94 97 Assert.AreEqual(4, parser.Columns); 95 98 Assert.AreEqual(parser.Values[3][0], 3.14); 96 } finally { 99 } 100 finally { 97 101 File.Delete(tempFileName); 98 102 } … … 118 122 Assert.AreEqual(4, parser.Columns); 119 123 Assert.AreEqual(parser.Values[3][0], 3.14); 120 } finally { 124 } 125 finally { 121 126 File.Delete(tempFileName); 122 127 } … … 141 146 Assert.AreEqual(4, parser.Columns); 142 147 Assert.AreEqual((double)parser.Values[3][0], 3); 143 } finally { 148 } 149 finally { 144 150 File.Delete(tempFileName); 145 151 } … … 165 171 Assert.AreEqual(4, parser.Columns); 166 172 Assert.AreEqual((double)parser.Values[3][0], 3); 167 } finally { 173 } 174 finally { 168 175 File.Delete(tempFileName); 169 176 } … … 188 195 Assert.AreEqual(4, parser.Columns); 189 196 Assert.AreEqual((double)parser.Values[3][0], 3); 190 } finally { 197 } 198 finally { 191 199 File.Delete(tempFileName); 192 200 } … … 211 219 Assert.AreEqual(4, parser.Columns); 212 220 Assert.AreEqual((double)parser.Values[3][0], 3); 213 } finally { 221 } 222 finally { 214 223 File.Delete(tempFileName); 215 224 } … … 235 244 Assert.AreEqual(4, parser.Columns); 236 245 Assert.AreEqual((double)parser.Values[3][0], 3); 237 } finally { 246 } 247 finally { 238 248 File.Delete(tempFileName); 239 249 } … … 259 269 Assert.AreEqual(4, parser.Columns); 260 270 Assert.AreEqual((double)parser.Values[3][0], 3); 261 } finally { 271 } 272 finally { 262 273 File.Delete(tempFileName); 263 274 } … … 283 294 Assert.AreEqual(4, parser.Columns); 284 295 Assert.AreEqual((double)parser.Values[3][0], 3.14); 285 } finally { 296 } 297 finally { 286 298 File.Delete(tempFileName); 287 299 } … … 307 319 Assert.AreEqual(4, parser.Columns); 308 320 Assert.AreEqual((double)parser.Values[3][0], 3.14); 309 } finally { 321 } 322 finally { 310 323 File.Delete(tempFileName); 311 324 } … … 330 343 Assert.AreEqual(4, parser.Columns); 331 344 Assert.AreEqual((double)parser.Values[3][0], 3.14); 332 } finally { 345 } 346 finally { 333 347 File.Delete(tempFileName); 334 348 } … … 354 368 Assert.AreEqual(4, parser.Columns); 355 369 Assert.AreEqual((double)parser.Values[3][0], 3.14); 356 } finally { 370 } 371 finally { 357 372 File.Delete(tempFileName); 358 373 } … … 377 392 Assert.AreEqual(4, parser.Columns); 378 393 Assert.AreEqual((double)parser.Values[3][0], 3); 379 } finally { 394 } 395 finally { 380 396 File.Delete(tempFileName); 381 397 } … … 401 417 Assert.AreEqual(4, parser.Columns); 402 418 Assert.AreEqual((double)parser.Values[3][0], 3); 403 } finally { 419 } 420 finally { 404 421 File.Delete(tempFileName); 405 422 } … … 424 441 Assert.AreEqual(4, parser.Rows); 425 442 Assert.AreEqual(4, parser.Columns); 426 } finally { 443 } 444 finally { 427 445 File.Delete(tempFileName); 428 446 } … … 447 465 Assert.AreEqual(4, parser.Columns); 448 466 Assert.AreEqual((double)parser.Values[3][0], 3.14); 449 } finally { 467 } 468 finally { 450 469 File.Delete(tempFileName); 451 470 } … … 471 490 Assert.AreEqual(4, parser.Columns); 472 491 Assert.AreEqual((double)parser.Values[3][0], 3.14); 473 } finally { 492 } 493 finally { 474 494 File.Delete(tempFileName); 475 495 } … … 494 514 Assert.AreEqual(4, parser.Columns); 495 515 Assert.AreEqual((double)parser.Values[3][0], 3.14); 496 } finally { 516 } 517 finally { 497 518 File.Delete(tempFileName); 498 519 } … … 518 539 Assert.AreEqual(4, parser.Columns); 519 540 Assert.AreEqual((double)parser.Values[3][0], 3.14); 520 } finally { 541 } 542 finally { 521 543 File.Delete(tempFileName); 522 544 } … … 539 561 Assert.AreEqual(3, parser.Rows); 540 562 Assert.AreEqual(4507, parser.Columns); 541 } finally { 563 } 564 finally { 542 565 File.Delete(tempFileName); 543 566 } … … 562 585 Assert.AreEqual(4, parser.Columns); 563 586 Assert.AreEqual((double)parser.Values[3][0], 3); 564 } finally { 587 } 588 finally { 565 589 File.Delete(tempFileName); 566 590 } … … 586 610 Assert.AreEqual(4, parser.Columns); 587 611 Assert.AreEqual((double)parser.Values[3][0], 3); 588 } finally { 612 } 613 finally { 589 614 File.Delete(tempFileName); 590 615 } … … 627 652 Assert.IsTrue(double.IsPositiveInfinity((double)parser.Values[1][3])); // NOTE: in DE-DE NumberFormat just "unendlich" is not allowed (compare with InvariantCulture) 628 653 Assert.IsTrue(double.IsNegativeInfinity((double)parser.Values[1][4])); 629 } finally { 654 } 655 finally { 630 656 File.Delete(tempFileName); 631 657 } … … 664 690 Assert.IsTrue(double.IsPositiveInfinity((double)parser.Values[1][3])); // NOTE: in InvariantCulture +Infinity is not allowed (compare with DE-DE) 665 691 Assert.IsTrue(double.IsNegativeInfinity((double)parser.Values[1][4])); 666 } finally { 667 File.Delete(tempFileName); 692 } 693 finally { 694 File.Delete(tempFileName); 695 } 696 } 697 698 699 [TestMethod] 700 [TestCategory("Problems.Instances")] 701 [TestProperty("Time", "short")] 702 public void ParseWithTypeConversion() { 703 // the parser tries to determine the column type (double, datetime, string) by looking at the values in the first few rows 704 // if the values are of a different type then the type of the column is converted 705 { 706 // case 1 707 // default for values is double and therefore a column with all missing values should be List<double> and contain NaN 708 var tmpFileName = Path.GetTempFileName(); 709 WriteToFile(tmpFileName, 710 @"stringCol,note 711 ,missing val 712 3.14,double 713 "); 714 715 TableFileParser parser = new TableFileParser(); 716 try { 717 parser.Parse(tmpFileName, 718 CultureInfo.InvariantCulture.NumberFormat, 719 CultureInfo.InvariantCulture.DateTimeFormat, 720 separator: ',', columnNamesInFirstLine: true); 721 Assert.IsTrue(parser.Values[0] is List<double>); 722 Assert.AreEqual(double.NaN, parser.Values[0][0]); 723 Assert.AreEqual(3.14, parser.Values[0][1]); 724 } 725 finally { 726 File.Delete(tmpFileName); 727 } 728 729 } 730 731 { 732 // case 2 733 // 'The first missing values are replaced with double.NaN while the last ones with string.Empty.' 734 735 var tmpFileName = Path.GetTempFileName(); 736 WriteToFile(tmpFileName, 737 @"stringCol,note 738 ,missing val 739 3.14, 740 ,missing val 741 str,a string --> column is converted to List<string> 742 ,missing val 743 "); 744 745 TableFileParser parser = new TableFileParser(); 746 try { 747 parser.Parse(tmpFileName, 748 CultureInfo.InvariantCulture.NumberFormat, 749 CultureInfo.InvariantCulture.DateTimeFormat, 750 separator: ',', columnNamesInFirstLine: true); 751 Assert.IsTrue(parser.Values[0] is List<string>); 752 Assert.AreEqual(string.Empty, parser.Values[0][0]); 753 Assert.AreEqual("3.14", parser.Values[0][1]); 754 Assert.AreEqual(string.Empty, parser.Values[0][2]); 755 Assert.AreEqual("str", parser.Values[0][3]); 756 Assert.AreEqual(string.Empty, parser.Values[0][4]); 757 } 758 finally { 759 File.Delete(tmpFileName); 760 } 761 } 762 763 { 764 // case 3 765 // DateTime conversion to strings 766 var tmpFileName = Path.GetTempFileName(); 767 WriteToFile(tmpFileName, 768 @"stringCol,note 769 ,missing val 770 3.1.2016, 771 ,missing val 772 str,a string --> column is converted to List<string> 773 ,missing val 774 "); 775 776 TableFileParser parser = new TableFileParser(); 777 try { 778 parser.Parse(tmpFileName, 779 CultureInfo.InvariantCulture.NumberFormat, 780 CultureInfo.InvariantCulture.DateTimeFormat, 781 separator: ',', columnNamesInFirstLine: true); 782 Assert.IsTrue(parser.Values[0] is List<string>); 783 Assert.AreEqual(string.Empty, parser.Values[0][0]); 784 Assert.AreEqual("3.1.2016", parser.Values[0][1]); 785 Assert.AreEqual(string.Empty, parser.Values[0][2]); 786 Assert.AreEqual("str", parser.Values[0][3]); 787 Assert.AreEqual(string.Empty, parser.Values[0][4]); 788 } 789 finally { 790 File.Delete(tmpFileName); 791 } 792 } 793 } 794 795 [TestMethod] 796 [TestCategory("Problems.Instances")] 797 [TestProperty("Time", "short")] 798 public void ParseDateTime() { 799 { 800 // case 1 dates and datetimes should be parsed as datetime column 801 var tmpFileName = Path.GetTempFileName(); 802 WriteToFile(tmpFileName, 803 @"stringCol,note 804 19.6.2016,date 805 19.6.2016 8:15,datetime 806 "); 807 808 TableFileParser parser = new TableFileParser(); 809 try { 810 parser.Parse(tmpFileName, 811 CultureInfo.GetCultureInfo("de-de").NumberFormat, 812 CultureInfo.GetCultureInfo("de-de").DateTimeFormat, 813 separator: ',', columnNamesInFirstLine: true); 814 Assert.IsTrue(parser.Values[0] is List<DateTime>); 815 Assert.AreEqual(new DateTime(2016, 6, 19), parser.Values[0][0]); 816 Assert.AreEqual(new DateTime(2016, 6, 19, 8, 15, 0), parser.Values[0][1]); 817 818 WriteToFile(tmpFileName, 819 @"stringCol,note 820 2016/6/19,date 821 2016/6/19 8:15,datetime 822 "); 823 824 parser.Parse(tmpFileName, 825 CultureInfo.InvariantCulture.NumberFormat, 826 CultureInfo.InvariantCulture.DateTimeFormat, 827 separator: ',', columnNamesInFirstLine: true); 828 Assert.IsTrue(parser.Values[0] is List<DateTime>); 829 Assert.AreEqual(new DateTime(2016, 6, 19), parser.Values[0][0]); 830 Assert.AreEqual(new DateTime(2016, 6, 19, 8, 15, 0), parser.Values[0][1]); 831 } 832 833 finally { 834 File.Delete(tmpFileName); 835 } 836 } 837 838 { 839 // case 2 never parse time values as datetimes 840 var tmpFileName = Path.GetTempFileName(); 841 WriteToFile(tmpFileName, 842 @"stringCol,note 843 8:15,time value 844 9:40,time value 845 "); 846 847 TableFileParser parser = new TableFileParser(); 848 try { 849 parser.Parse(tmpFileName, 850 CultureInfo.InvariantCulture.NumberFormat, 851 CultureInfo.InvariantCulture.DateTimeFormat, 852 separator: ',', columnNamesInFirstLine: true); 853 Assert.IsTrue(parser.Values[0] is List<string>); // time values should be parsed as strings 854 Assert.AreEqual("8:15", parser.Values[0][0]); 855 Assert.AreEqual("9:40", parser.Values[0][1]); 856 } 857 finally { 858 File.Delete(tmpFileName); 859 } 860 } 861 } 862 863 864 865 [TestMethod] 866 [TestCategory("Problems.Instances")] 867 [TestProperty("Time", "short")] 868 public void CheckTypeConversionAndLongFiles() { 869 { 870 // case 1 incorrect input after 500 rows should lead to exceptions 871 var tmpFileName = Path.GetTempFileName(); 872 // create input data 873 var sb = new StringBuilder(); 874 sb.AppendLine("col1,col2"); 875 for (int r = 0; r < 2000; r++) { 876 sb.AppendLine("3.15, 3.15"); 877 } 878 // add a row with only one input value 879 sb.AppendLine("3.15"); 880 881 WriteToFile(tmpFileName, sb.ToString()); 882 883 TableFileParser parser = new TableFileParser(); 884 try { 885 parser.Parse(tmpFileName, 886 CultureInfo.InvariantCulture.NumberFormat, 887 CultureInfo.InvariantCulture.DateTimeFormat, 888 separator: ',', columnNamesInFirstLine: true); 889 // Parse should fail with an exception 890 Assert.Fail("expected exception TableFileParser.DataFormatException"); 891 } 892 catch (IOException) { 893 // ignore the expected exception 894 } 895 896 finally { 897 File.Delete(tmpFileName); 898 } 899 } 900 { 901 // case 2 902 var tmpFileName = Path.GetTempFileName(); 903 // create input data 904 var sb = new StringBuilder(); 905 sb.AppendLine("doubleCol,stringCol"); 906 for (int r = 0; r < 2000; r++) { 907 sb.AppendLine("3.15, 3.15"); 908 } 909 // add a row with a string value --> the column should be converted to string 910 sb.AppendLine("3.15,str"); 911 912 WriteToFile(tmpFileName, sb.ToString()); 913 914 TableFileParser parser = new TableFileParser(); 915 try { 916 parser.Parse(tmpFileName, 917 CultureInfo.InvariantCulture.NumberFormat, 918 CultureInfo.InvariantCulture.DateTimeFormat, 919 separator: ',', columnNamesInFirstLine: true); 920 Assert.IsTrue(parser.Values[0] is List<double>); 921 Assert.IsTrue(parser.Values[1] is List<string>); 922 Assert.AreEqual(parser.Values[1][0], "3.15"); 923 Assert.AreEqual(parser.Values[1][2000], "str"); 924 } 925 926 finally { 927 File.Delete(tmpFileName); 928 } 668 929 } 669 930 }
Note: See TracChangeset
for help on using the changeset viewer.