Changeset 16084


Ignore:
Timestamp:
08/17/18 09:35:52 (12 months ago)
Author:
jkarder
Message:

#2939:

  • allowed variables to be added if dataset contains no rows
  • refactored AddVariable to use InsertVariable
Location:
trunk/HeuristicLab.Problems.DataAnalysis/3.4
Files:
2 edited

Legend:

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

    r16063 r16084  
    116116
    117117    public ModifiableDataset ToModifiable() {
    118       return new ModifiableDataset(variableNames, variableNames.Select(v => variableValues[v]),true);
     118      return new ModifiableDataset(variableNames, variableNames.Select(v => variableValues[v]), true);
    119119    }
    120120
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs

    r16063 r16084  
    101101    // adds a new variable to the dataset
    102102    public void AddVariable(string variableName, IList values) {
    103       if (variableValues.ContainsKey(variableName))
    104         throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName));
    105 
    106       if (values == null || values.Count == 0)
    107         throw new ArgumentException("Cannot add variable with no values.");
    108 
    109       if (values.Count != Rows)
    110         throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows));
    111 
    112       if (!IsAllowedType(values))
    113         throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));
    114 
    115       variableValues[variableName] = values;
    116       variableNames.Add(variableName);
    117 
    118       OnColumnsChanged();
    119       OnColumnNamesChanged();
    120       OnReset();
     103      InsertVariable(variableName, Columns, values);
    121104    }
    122105
     
    129112        throw new ArgumentException(string.Format("Incorrect position {0} specified. The position must be between 0 and {1}.", position, Columns));
    130113
    131       if (values == null || values.Count == 0)
    132         throw new ArgumentException("Cannot add variable with no values.");
     114      if (values == null)
     115        throw new ArgumentNullException("values", "Values must not be null. At least an empty list of values has to be provided.");
    133116
    134117      if (values.Count != Rows)
Note: See TracChangeset for help on using the changeset viewer.