Changeset 13949


Ignore:
Timestamp:
06/29/16 13:56:59 (3 years ago)
Author:
mkommend
Message:

#2593: Merged r13760 and r13761 into stable.

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis

  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r13881 r13949  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    118118    }
    119119
     120    public ModifiableDataset ToModifiable() {
     121      var values = new List<IList>();
     122      foreach (var v in variableNames) {
     123        if (VariableHasType<double>(v)) {
     124          values.Add(new List<double>((List<double>)variableValues[v]));
     125        } else if (VariableHasType<string>(v)) {
     126          values.Add(new List<string>((List<string>)variableValues[v]));
     127        } else if (VariableHasType<DateTime>(v)) {
     128          values.Add(new List<DateTime>((List<DateTime>)variableValues[v]));
     129        } else {
     130          throw new ArgumentException("Unknown variable type.");
     131        }
     132      }
     133      return new ModifiableDataset(variableNames, values);
     134    }
     135
    120136    protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { }
    121137
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs

    r13179 r13949  
    22
    33/* HeuristicLab
    4  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
     
    5656    public ModifiableDataset() : base() { }
    5757
    58     public ModifiableDataset(Dataset dataset) : base(dataset) { }
    5958    public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) : base(variableNames, variableValues) { }
    6059
     
    7473      }
    7574      OnReset();
     75    }
     76
     77    public void ReplaceVariable(string variableName, IList values) {
     78      if (!variableValues.ContainsKey(variableName))
     79        throw new ArgumentException(string.Format("Variable {0} is not present in the dataset."), variableName);
     80      if (values.Count != variableValues[variableName].Count)
     81        throw new ArgumentException("The number of values must coincide with the number of dataset rows.");
     82      if (GetVariableType(variableName) != values[0].GetType())
     83        throw new ArgumentException("The type of the provided value does not match the variable type.");
     84      variableValues[variableName] = values;
    7685    }
    7786
Note: See TracChangeset for help on using the changeset viewer.