Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13760


Ignore:
Timestamp:
04/14/16 13:33:02 (9 years ago)
Author:
bburlacu
Message:

#2593: Add ToModifiable method to the Dataset class. Add ReplaceColumn method to the ModifiableDataset.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4
Files:
2 edited

Legend:

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

    r13539 r13760  
    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.
     
    111111    }
    112112
     113    public ModifiableDataset ToModifiable() {
     114      var values = new List<IList>();
     115      foreach (var v in variableNames) {
     116        if (VariableHasType<double>(v)) {
     117          values.Add(((List<double>)variableValues[v]).ToList());
     118        } else if (VariableHasType<string>(v)) {
     119          values.Add(((List<string>)variableValues[v]).ToList());
     120        } else if (VariableHasType<DateTime>(v)) {
     121          values.Add(((List<DateTime>)variableValues[v]).ToList());
     122        } else {
     123          throw new ArgumentException("Unknown variable type.");
     124        }
     125      }
     126      return new ModifiableDataset(variableNames, values);
     127    }
     128
    113129    protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { }
    114130
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs

    r13040 r13760  
    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 ReplaceColumn<T>(string variableName, List<T> 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.