@@ -41,11 +41,23 @@ internal IReadOnlyList<string> GetColumnNames()
4141 return ret ;
4242 }
4343
44+ public void RenameColumn ( string currentName , string newName )
45+ {
46+ var column = this [ currentName ] ;
47+ column . SetName ( newName ) ;
48+ }
49+
50+ [ Obsolete ]
4451 public void SetColumnName ( DataFrameColumn column , string newName )
52+ {
53+ column . SetName ( newName ) ;
54+ }
55+
56+ //Updates column's metadata (is used as a callback from Column class)
57+ internal void UpdateColumnNameMetadata ( DataFrameColumn column , string newName )
4558 {
4659 string currentName = column . Name ;
4760 int currentIndex = _columnNameToIndexDictionary [ currentName ] ;
48- column . SetName ( newName ) ;
4961 _columnNames [ currentIndex ] = newName ;
5062 _columnNameToIndexDictionary . Remove ( currentName ) ;
5163 _columnNameToIndexDictionary . Add ( newName , currentIndex ) ;
@@ -76,6 +88,9 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column)
7688 {
7789 throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
7890 }
91+
92+ column . AddOwner ( this ) ;
93+
7994 RowCount = column . Length ;
8095 _columnNames . Insert ( columnIndex , column . Name ) ;
8196 _columnNameToIndexDictionary [ column . Name ] = columnIndex ;
@@ -99,10 +114,14 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
99114 {
100115 throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
101116 }
117+
102118 _columnNameToIndexDictionary . Remove ( _columnNames [ columnIndex ] ) ;
103119 _columnNames [ columnIndex ] = column . Name ;
104120 _columnNameToIndexDictionary [ column . Name ] = columnIndex ;
121+
122+ this [ columnIndex ] . RemoveOwner ( this ) ;
105123 base . SetItem ( columnIndex , column ) ;
124+
106125 ColumnsChanged ? . Invoke ( ) ;
107126 }
108127
@@ -114,7 +133,10 @@ protected override void RemoveItem(int columnIndex)
114133 _columnNameToIndexDictionary [ _columnNames [ i ] ] -- ;
115134 }
116135 _columnNames . RemoveAt ( columnIndex ) ;
136+
137+ this [ columnIndex ] . RemoveOwner ( this ) ;
117138 base . RemoveItem ( columnIndex ) ;
139+
118140 ColumnsChanged ? . Invoke ( ) ;
119141 }
120142
0 commit comments