Skip to content

Commit 9590b07

Browse files
authored
Remove redundant column names collection from DataFrameColumnCollection (#6701)
1 parent 564dfae commit 9590b07

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs

+4-12
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ namespace Microsoft.Data.Analysis
1414
public class DataFrameColumnCollection : Collection<DataFrameColumn>
1515
{
1616
private readonly Action ColumnsChanged;
17-
18-
private readonly List<string> _columnNames = new List<string>();
19-
2017
private readonly Dictionary<string, int> _columnNameToIndexDictionary = new Dictionary<string, int>(StringComparer.Ordinal);
2118

2219
internal long RowCount { get; set; }
@@ -46,7 +43,6 @@ public void SetColumnName(DataFrameColumn column, string newName)
4643
string currentName = column.Name;
4744
int currentIndex = _columnNameToIndexDictionary[currentName];
4845
column.SetName(newName);
49-
_columnNames[currentIndex] = newName;
5046
_columnNameToIndexDictionary.Remove(currentName);
5147
_columnNameToIndexDictionary.Add(newName, currentIndex);
5248
ColumnsChanged?.Invoke();
@@ -77,11 +73,10 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column)
7773
throw new ArgumentException(string.Format(Strings.DuplicateColumnName, column.Name), nameof(column));
7874
}
7975
RowCount = column.Length;
80-
_columnNames.Insert(columnIndex, column.Name);
8176
_columnNameToIndexDictionary[column.Name] = columnIndex;
8277
for (int i = columnIndex + 1; i < Count; i++)
8378
{
84-
_columnNameToIndexDictionary[_columnNames[i]]++;
79+
_columnNameToIndexDictionary[this[i].Name]++;
8580
}
8681
base.InsertItem(columnIndex, column);
8782
ColumnsChanged?.Invoke();
@@ -99,21 +94,19 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
9994
{
10095
throw new ArgumentException(string.Format(Strings.DuplicateColumnName, column.Name), nameof(column));
10196
}
102-
_columnNameToIndexDictionary.Remove(_columnNames[columnIndex]);
103-
_columnNames[columnIndex] = column.Name;
97+
_columnNameToIndexDictionary.Remove(this[columnIndex].Name);
10498
_columnNameToIndexDictionary[column.Name] = columnIndex;
10599
base.SetItem(columnIndex, column);
106100
ColumnsChanged?.Invoke();
107101
}
108102

109103
protected override void RemoveItem(int columnIndex)
110104
{
111-
_columnNameToIndexDictionary.Remove(_columnNames[columnIndex]);
105+
_columnNameToIndexDictionary.Remove(this[columnIndex].Name);
112106
for (int i = columnIndex + 1; i < Count; i++)
113107
{
114-
_columnNameToIndexDictionary[_columnNames[i]]--;
108+
_columnNameToIndexDictionary[this[i].Name]--;
115109
}
116-
_columnNames.RemoveAt(columnIndex);
117110
base.RemoveItem(columnIndex);
118111
ColumnsChanged?.Invoke();
119112
}
@@ -144,7 +137,6 @@ protected override void ClearItems()
144137
{
145138
base.ClearItems();
146139
ColumnsChanged?.Invoke();
147-
_columnNames.Clear();
148140
_columnNameToIndexDictionary.Clear();
149141
}
150142

0 commit comments

Comments
 (0)