@@ -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 ; }
@@ -58,7 +55,6 @@ internal void UpdateColumnNameMetadata(DataFrameColumn column, string newName)
5855 {
5956 string currentName = column . Name ;
6057 int currentIndex = _columnNameToIndexDictionary [ currentName ] ;
61- _columnNames [ currentIndex ] = newName ;
6258 _columnNameToIndexDictionary . Remove ( currentName ) ;
6359 _columnNameToIndexDictionary . Add ( newName , currentIndex ) ;
6460 ColumnsChanged ? . Invoke ( ) ;
@@ -93,11 +89,10 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column)
9389
9490 column . AddOwner ( this ) ;
9591
96- _columnNames . Insert ( columnIndex , column . Name ) ;
9792 _columnNameToIndexDictionary [ column . Name ] = columnIndex ;
9893 for ( int i = columnIndex + 1 ; i < Count ; i ++ )
9994 {
100- _columnNameToIndexDictionary [ _columnNames [ i ] ] ++ ;
95+ _columnNameToIndexDictionary [ this [ i ] . Name ] ++ ;
10196 }
10297 base . InsertItem ( columnIndex , column ) ;
10398 ColumnsChanged ? . Invoke ( ) ;
@@ -115,9 +110,7 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
115110 {
116111 throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
117112 }
118-
119- _columnNameToIndexDictionary . Remove ( _columnNames [ columnIndex ] ) ;
120- _columnNames [ columnIndex ] = column . Name ;
113+ _columnNameToIndexDictionary . Remove ( this [ columnIndex ] . Name ) ;
121114 _columnNameToIndexDictionary [ column . Name ] = columnIndex ;
122115
123116 this [ columnIndex ] . RemoveOwner ( this ) ;
@@ -128,12 +121,11 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
128121
129122 protected override void RemoveItem ( int columnIndex )
130123 {
131- _columnNameToIndexDictionary . Remove ( _columnNames [ columnIndex ] ) ;
124+ _columnNameToIndexDictionary . Remove ( this [ columnIndex ] . Name ) ;
132125 for ( int i = columnIndex + 1 ; i < Count ; i ++ )
133126 {
134- _columnNameToIndexDictionary [ _columnNames [ i ] ] -- ;
127+ _columnNameToIndexDictionary [ this [ i ] . Name ] -- ;
135128 }
136- _columnNames . RemoveAt ( columnIndex ) ;
137129
138130 this [ columnIndex ] . RemoveOwner ( this ) ;
139131 base . RemoveItem ( columnIndex ) ;
@@ -171,7 +163,6 @@ protected override void ClearItems()
171163 {
172164 base . ClearItems ( ) ;
173165 ColumnsChanged ? . Invoke ( ) ;
174- _columnNames . Clear ( ) ;
175166 _columnNameToIndexDictionary . Clear ( ) ;
176167
177168 //reset RowCount as DataFrame is now empty
0 commit comments