@@ -41,11 +41,23 @@ internal IReadOnlyList<string> GetColumnNames()
41
41
return ret ;
42
42
}
43
43
44
+ public void RenameColumn ( string currentName , string newName )
45
+ {
46
+ var column = this [ currentName ] ;
47
+ column . SetName ( newName ) ;
48
+ }
49
+
50
+ [ Obsolete ]
44
51
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 )
45
58
{
46
59
string currentName = column . Name ;
47
60
int currentIndex = _columnNameToIndexDictionary [ currentName ] ;
48
- column . SetName ( newName ) ;
49
61
_columnNames [ currentIndex ] = newName ;
50
62
_columnNameToIndexDictionary . Remove ( currentName ) ;
51
63
_columnNameToIndexDictionary . Add ( newName , currentIndex ) ;
@@ -76,6 +88,9 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column)
76
88
{
77
89
throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
78
90
}
91
+
92
+ column . AddOwner ( this ) ;
93
+
79
94
RowCount = column . Length ;
80
95
_columnNames . Insert ( columnIndex , column . Name ) ;
81
96
_columnNameToIndexDictionary [ column . Name ] = columnIndex ;
@@ -99,10 +114,14 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
99
114
{
100
115
throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
101
116
}
117
+
102
118
_columnNameToIndexDictionary . Remove ( _columnNames [ columnIndex ] ) ;
103
119
_columnNames [ columnIndex ] = column . Name ;
104
120
_columnNameToIndexDictionary [ column . Name ] = columnIndex ;
121
+
122
+ this [ columnIndex ] . RemoveOwner ( this ) ;
105
123
base . SetItem ( columnIndex , column ) ;
124
+
106
125
ColumnsChanged ? . Invoke ( ) ;
107
126
}
108
127
@@ -114,7 +133,10 @@ protected override void RemoveItem(int columnIndex)
114
133
_columnNameToIndexDictionary [ _columnNames [ i ] ] -- ;
115
134
}
116
135
_columnNames . RemoveAt ( columnIndex ) ;
136
+
137
+ this [ columnIndex ] . RemoveOwner ( this ) ;
117
138
base . RemoveItem ( columnIndex ) ;
139
+
118
140
ColumnsChanged ? . Invoke ( ) ;
119
141
}
120
142
0 commit comments