- Timestamp:
- 09/06/18 12:19:23 (6 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 15769,15829
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis (added) merged: 15769,15829
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
r15584 r16124 39 39 40 40 private ModifiableDataset(ModifiableDataset original, Cloner cloner) : base(original, cloner) { 41 var variables = variableValues.Keys.ToList(); 42 foreach (var v in variables) { 43 var type = GetVariableType(v); 44 if (type == typeof(DateTime)) { 45 variableValues[v] = GetDateTimeValues(v).ToList(); 46 } else if (type == typeof(double)) { 47 variableValues[v] = GetDoubleValues(v).ToList(); 48 } else if (type == typeof(string)) { 49 variableValues[v] = GetStringValues(v).ToList(); 50 } else { 51 throw new ArgumentException("Unsupported type " + type + " for variable " + v); 52 } 53 } 54 } 41 variableNames = new List<string>(original.variableNames); 42 variableValues = CloneValues(original.variableValues); 43 } 44 55 45 public override IDeepCloneable Clone(Cloner cloner) { return new ModifiableDataset(this, cloner); } 56 public ModifiableDataset() : base() { } 57 58 public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) : base(variableNames, variableValues) { } 46 47 public ModifiableDataset() { } 48 49 public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) : 50 base(variableNames, variableValues, cloneValues: false) { } 59 51 60 52 public void ReplaceRow(int row, IEnumerable<object> values) { … … 105 97 106 98 // adds a new variable to the dataset 107 public void AddVariable <T>(string variableName, IEnumerable<T>values) {99 public void AddVariable(string variableName, IList values) { 108 100 if (variableValues.ContainsKey(variableName)) 109 throw new ArgumentException("Variable " + variableName + " is already present in the dataset."); 110 int count = values.Count(); 111 if (count != rows) 112 throw new ArgumentException("The number of values must exactly match the number of rows in the dataset."); 113 variableValues[variableName] = new List<T>(values); 101 throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName)); 102 103 if (values == null || values.Count == 0) 104 throw new ArgumentException("Cannot add variable with no values."); 105 106 if (!IsAllowedType(values)) 107 throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName)); 108 109 variableValues[variableName] = values; 114 110 variableNames.Add(variableName); 111 115 112 OnColumnsChanged(); 116 113 OnColumnNamesChanged(); … … 120 117 public void RemoveVariable(string variableName) { 121 118 if (!variableValues.ContainsKey(variableName)) 122 throw new ArgumentException( "The variable " + variableName + " does not exist in the dataset.");119 throw new ArgumentException(string.Format("The variable {0} does not exist in the dataset.", variableName)); 123 120 variableValues.Remove(variableName); 124 121 variableNames.Remove(variableName); … … 128 125 } 129 126 130 // slow, avoid to usethis127 // slow, avoid using this 131 128 public void RemoveRow(int row) { 132 129 foreach (var list in variableValues.Values) … … 151 148 } 152 149 153 private Type GetVariableType(string variableName) {154 IList list;155 variableValues.TryGetValue(variableName, out list);156 if (list == null)157 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");158 return list.GetType().GetGenericArguments()[0];159 }160 161 150 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) { 162 151 var variableName = variableNames[columnIndex];
Note: See TracChangeset
for help on using the changeset viewer.