Ignore:
Timestamp:
11/19/15 12:02:40 (7 years ago)
Author:
mkommend
Message:

#2486: Merged r12983, r12986, r13252 and r13271 into stable.

Location:
stable
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.DataPreprocessing/3.4

  • stable/HeuristicLab.DataPreprocessing/3.4/Implementations/DataGridContent.cs

    r12718 r13289  
    4141    public IFilterLogic FilterLogic { get; private set; }
    4242
    43     private IEnumerable<string> rowNames;
    44 
    4543    public int Rows {
    4644      get {
     
    7270    public IEnumerable<string> RowNames {
    7371      get {
    74         return rowNames;
     72        return Enumerable.Range(1, Rows).Select(n => n.ToString());
    7573      }
    7674      set {
    77         //not supported
     75        throw new NotSupportedException();
    7876      }
    7977    }
     
    8482      }
    8583      set {
    86         //not supported
     84        throw new NotSupportedException();
    8785      }
    8886    }
     
    103101      FilterLogic = theFilterLogic;
    104102      PreProcessingData = preProcessingData;
    105       createRowNames();
    106103    }
    107104
     
    116113    public void DeleteRows(IEnumerable<int> rows) {
    117114      PreProcessingData.DeleteRowsWithIndices(rows);
    118       createRowNames();
    119115    }
    120116
     
    133129    public bool SetValue(string value, int rowIndex, int columnIndex) {
    134130      return PreProcessingData.SetValue(value, columnIndex, rowIndex);
    135     }
    136 
    137     private void createRowNames() {
    138       rowNames = Enumerable.Range(1, Rows).Select(n => n.ToString());
    139131    }
    140132
  • stable/HeuristicLab.DataPreprocessing/3.4/Implementations/FilteredPreprocessingData.cs

    r12121 r13289  
    119119        throw new InvalidOperationException("DeleteColumn not possible while data is filtered");
    120120      originalData.DeleteColumn(columnIndex);
     121    }
     122
     123    public void RenameColumn(int columnIndex, string name) {
     124      if (IsFiltered)
     125        throw new InvalidOperationException("RenameColumn not possible while data is filtered");
     126      originalData.RenameColumn(columnIndex, name);
     127    }
     128
     129    public void RenameColumns(IList<string> names) {
     130      if (IsFiltered)
     131        throw new InvalidOperationException("RenameColumns not possible while data is filtered");
     132      originalData.RenameColumns(names);
    121133    }
    122134
  • stable/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingData.cs

    r12702 r13289  
    196196    public abstract void DeleteColumn(int columnIndex);
    197197
     198    public abstract void RenameColumn(int columnIndex, string name);
     199    public abstract void RenameColumns(IList<string> list);
     200
    198201    public abstract Dataset ExportToDataset();
    199202
  • stable/HeuristicLab.DataPreprocessing/3.4/Implementations/TransactionalPreprocessingData.cs

    r12009 r13289  
    9898    public override void SetCell<T>(int columnIndex, int rowIndex, T value) {
    9999      SaveSnapshot(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex);
     100
     101      for (int i = Rows; i <= rowIndex; i++)
     102        InsertRow(i);
     103      for (int i = Columns; i <= columnIndex; i++)
     104        InsertColumn<T>(i.ToString(), i);
     105
    100106      variableValues[columnIndex][rowIndex] = value;
    101107      if (!IsInTransaction)
     
    116122
    117123    public override bool VariableHasType<T>(int columnIndex) {
    118       return variableValues[columnIndex] is List<T>;
     124      return columnIndex >= variableValues.Count || variableValues[columnIndex] is List<T>;
    119125    }
    120126
     
    219225      if (!IsInTransaction)
    220226        OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, -1);
     227      ResetPartitions();
    221228    }
    222229
     
    229236      if (!IsInTransaction)
    230237        OnChanged(DataPreprocessingChangedEventType.AddRow, -1, rowIndex);
     238      ResetPartitions();
    231239    }
    232240
     
    238246      if (!IsInTransaction)
    239247        OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex);
     248      ResetPartitions();
    240249    }
    241250
    242251    public override void InsertColumn<T>(string variableName, int columnIndex) {
    243252      SaveSnapshot(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1);
    244       variableValues.Insert(columnIndex, new List<T>(Rows));
     253      variableValues.Insert(columnIndex, new List<T>(Enumerable.Repeat(default(T), Rows)));
    245254      variableNames.Insert(columnIndex, variableName);
    246255      if (!IsInTransaction)
     
    256265    }
    257266
     267    public override void RenameColumn(int columnIndex, string name) {
     268      SaveSnapshot(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
     269      if (columnIndex < 0 || columnIndex > variableNames.Count)
     270        throw new ArgumentOutOfRangeException("columnIndex");
     271      variableNames[columnIndex] = name;
     272
     273      if (!IsInTransaction)
     274        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, -1, -1);
     275    }
     276
     277    public override void RenameColumns(IList<string> names) {
     278      if (names == null) throw new ArgumentNullException("names");
     279      if (names.Count != variableNames.Count) throw new ArgumentException("number of names must match the number of columns.", "names");
     280
     281      SaveSnapshot(DataPreprocessingChangedEventType.ChangeColumn, -1, -1);
     282      for (int i = 0; i < names.Count; i++)
     283        variableNames[i] = names[i];
     284
     285      if (!IsInTransaction)
     286        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, -1, -1);
     287    }
     288
    258289    public override Dataset ExportToDataset() {
    259290      IList<IList> values = new List<IList>();
     
    278309    }
    279310
     311
     312    private void ResetPartitions() {
     313      TrainingPartition = new IntRange();
     314      TestPartition = new IntRange();
     315    }
    280316
    281317    #endregion
  • stable/HeuristicLab.DataPreprocessing/3.4/Interfaces/IPreprocessingData.cs

    r12121 r13289  
    4747    void DeleteColumn(int columnIndex);
    4848
     49    void RenameColumn(int columnIndex, string name);
     50    void RenameColumns(IList<string> names);
     51
    4952    bool AreAllStringColumns(IEnumerable<int> columnIndices);
    5053    bool Validate(string value, out string errorMessage, int columnIndex);
  • stable/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs

    r12718 r13289  
    6363      var inputVariables = oldProblemData.InputVariables.ToDictionary(x => x.Value, x => x);
    6464      foreach (var variable in problemData.InputVariables) {
    65         bool isChecked = oldProblemData.InputVariables.ItemChecked(inputVariables[variable.Value]);
     65        bool isChecked = inputVariables.ContainsKey(variable.Value) && oldProblemData.InputVariables.ItemChecked(inputVariables[variable.Value]);
    6666        problemData.InputVariables.SetItemCheckedState(variable, isChecked);
    6767      }
     
    7272    private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData) {
    7373      var targetVariable = oldProblemData.TargetVariable;
    74       // target variable must be double and must exist in the new dataset
    75       return new RegressionProblemData(ExportedDataset, GetDoubleInputVariables(targetVariable), targetVariable, Transformations);
     74      if (!context.Data.VariableNames.Contains(targetVariable))
     75        targetVariable = context.Data.VariableNames.First();
     76      var inputVariables = GetDoubleInputVariables(targetVariable);
     77      var newProblemData = new RegressionProblemData(ExportedDataset, inputVariables, targetVariable, Transformations);
     78      return newProblemData;
    7679    }
    7780
    7881    private IDataAnalysisProblemData CreateClassificationData(ClassificationProblemData oldProblemData) {
    79       // target variable must be double and must exist in the new dataset
    8082      var targetVariable = oldProblemData.TargetVariable;
    81       var newProblemData = new ClassificationProblemData(ExportedDataset, GetDoubleInputVariables(targetVariable), targetVariable, Transformations);
     83      if (!context.Data.VariableNames.Contains(targetVariable))
     84        targetVariable = context.Data.VariableNames.First();
     85      var inputVariables = GetDoubleInputVariables(targetVariable);
     86      var newProblemData = new ClassificationProblemData(ExportedDataset, inputVariables, targetVariable, Transformations);
    8287      newProblemData.PositiveClass = oldProblemData.PositiveClass;
    8388      return newProblemData;
Note: See TracChangeset for help on using the changeset viewer.