Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ namespace Microsoft.Data.Analysis
public class DataFrameColumnCollection : Collection<DataFrameColumn>
{
private readonly Action ColumnsChanged;

private readonly List<string> _columnNames = new List<string>();

private readonly Dictionary<string, int> _columnNameToIndexDictionary = new Dictionary<string, int>(StringComparer.Ordinal);

internal long RowCount { get; set; }
Expand Down Expand Up @@ -46,7 +43,6 @@ public void SetColumnName(DataFrameColumn column, string newName)
string currentName = column.Name;
int currentIndex = _columnNameToIndexDictionary[currentName];
column.SetName(newName);
_columnNames[currentIndex] = newName;
_columnNameToIndexDictionary.Remove(currentName);
_columnNameToIndexDictionary.Add(newName, currentIndex);
ColumnsChanged?.Invoke();
Expand Down Expand Up @@ -77,11 +73,10 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column)
throw new ArgumentException(string.Format(Strings.DuplicateColumnName, column.Name), nameof(column));
}
RowCount = column.Length;
_columnNames.Insert(columnIndex, column.Name);
_columnNameToIndexDictionary[column.Name] = columnIndex;
for (int i = columnIndex + 1; i < Count; i++)
{
_columnNameToIndexDictionary[_columnNames[i]]++;
_columnNameToIndexDictionary[this[i].Name]++;
}
base.InsertItem(columnIndex, column);
ColumnsChanged?.Invoke();
Expand All @@ -99,21 +94,19 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
{
throw new ArgumentException(string.Format(Strings.DuplicateColumnName, column.Name), nameof(column));
}
_columnNameToIndexDictionary.Remove(_columnNames[columnIndex]);
_columnNames[columnIndex] = column.Name;
_columnNameToIndexDictionary.Remove(this[columnIndex].Name);
_columnNameToIndexDictionary[column.Name] = columnIndex;
base.SetItem(columnIndex, column);
ColumnsChanged?.Invoke();
}

protected override void RemoveItem(int columnIndex)
{
_columnNameToIndexDictionary.Remove(_columnNames[columnIndex]);
_columnNameToIndexDictionary.Remove(this[columnIndex].Name);
for (int i = columnIndex + 1; i < Count; i++)
{
_columnNameToIndexDictionary[_columnNames[i]]--;
_columnNameToIndexDictionary[this[i].Name]--;
}
_columnNames.RemoveAt(columnIndex);
base.RemoveItem(columnIndex);
ColumnsChanged?.Invoke();
}
Expand Down Expand Up @@ -144,7 +137,6 @@ protected override void ClearItems()
{
base.ClearItems();
ColumnsChanged?.Invoke();
_columnNames.Clear();
_columnNameToIndexDictionary.Clear();
}

Expand Down