Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6776


Ignore:
Timestamp:
09/16/11 08:28:12 (11 years ago)
Author:
gkronber
Message:

#1640 fixed a bug in parsing datetime values and improved code for filling dataset columns

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/TableFileParser.cs

    r6742 r6776  
    9898        }
    9999
    100         var columnType = types.GroupBy(v => v).OrderBy(v => v).Last().Key;
     100        var columnType = types.GroupBy(v => v).OrderBy(v => v.Count()).Last().Key;
    101101        if (columnType == typeof(double)) values.Add(new List<double>());
    102102        else if (columnType == typeof(DateTime)) values.Add(new List<DateTime>());
     
    111111        int columnIndex = 0;
    112112        foreach (object element in row) {
    113           //handle missing values with default values
    114           if (element as string == string.Empty) {
    115             if (values[columnIndex] is List<double>) values[columnIndex].Add(double.NaN);
    116             else if (values[columnIndex] is List<DateTime>) values[columnIndex].Add(DateTime.MinValue);
    117             else if (values[columnIndex] is List<string>) values[columnIndex].Add(string.Empty);
    118             else throw new InvalidOperationException();
    119           } else values[columnIndex].Add(element);
     113          if (values[columnIndex] is List<double> && !(element is double))
     114            values[columnIndex].Add(double.NaN);
     115          else if (values[columnIndex] is List<DateTime> && !(element is DateTime))
     116            values[columnIndex].Add(DateTime.MinValue);
     117          else if (values[columnIndex] is List<string> && !(element is string))
     118            values[columnIndex].Add(string.Empty);
     119          else
     120            values[columnIndex].Add(element);
    120121          columnIndex++;
    121122        }
     
    296297          token.type = TokenTypeEnum.Double;
    297298          return token;
    298         } else if (DateTime.TryParse(strToken, out token.dateTimeValue)) {
     299        } else if (DateTime.TryParse(strToken, dateTimeFormatInfo, DateTimeStyles.None, out token.dateTimeValue)) {
    299300          token.type = TokenTypeEnum.DateTime;
    300301          return token;
Note: See TracChangeset for help on using the changeset viewer.