@@ -38,11 +38,23 @@ internal IReadOnlyList<string> GetColumnNames()
38
38
return ret ;
39
39
}
40
40
41
+ public void RenameColumn ( string currentName , string newName )
42
+ {
43
+ var column = this [ currentName ] ;
44
+ column . SetName ( newName ) ;
45
+ }
46
+
47
+ [ Obsolete ]
41
48
public void SetColumnName ( DataFrameColumn column , string newName )
49
+ {
50
+ column . SetName ( newName ) ;
51
+ }
52
+
53
+ //Updates column's metadata (is used as a callback from Column class)
54
+ internal void UpdateColumnNameMetadata ( DataFrameColumn column , string newName )
42
55
{
43
56
string currentName = column . Name ;
44
57
int currentIndex = _columnNameToIndexDictionary [ currentName ] ;
45
- column . SetName ( newName ) ;
46
58
_columnNameToIndexDictionary . Remove ( currentName ) ;
47
59
_columnNameToIndexDictionary . Add ( newName , currentIndex ) ;
48
60
ColumnsChanged ? . Invoke ( ) ;
@@ -75,6 +87,8 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column)
75
87
throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
76
88
}
77
89
90
+ column . AddOwner ( this ) ;
91
+
78
92
RowCount = column . Length ;
79
93
80
94
_columnNameToIndexDictionary [ column . Name ] = columnIndex ;
@@ -98,9 +112,13 @@ protected override void SetItem(int columnIndex, DataFrameColumn column)
98
112
{
99
113
throw new ArgumentException ( string . Format ( Strings . DuplicateColumnName , column . Name ) , nameof ( column ) ) ;
100
114
}
115
+
101
116
_columnNameToIndexDictionary . Remove ( this [ columnIndex ] . Name ) ;
102
117
_columnNameToIndexDictionary [ column . Name ] = columnIndex ;
118
+
119
+ this [ columnIndex ] . RemoveOwner ( this ) ;
103
120
base . SetItem ( columnIndex , column ) ;
121
+
104
122
ColumnsChanged ? . Invoke ( ) ;
105
123
}
106
124
@@ -111,6 +129,8 @@ protected override void RemoveItem(int columnIndex)
111
129
{
112
130
_columnNameToIndexDictionary [ this [ i ] . Name ] -- ;
113
131
}
132
+
133
+ this [ columnIndex ] . RemoveOwner ( this ) ;
114
134
base . RemoveItem ( columnIndex ) ;
115
135
116
136
//Reset RowCount if the last column was removed and dataframe is empty
@@ -474,6 +494,5 @@ public UInt16DataFrameColumn GetUInt16Column(string name)
474
494
475
495
throw new ArgumentException ( string . Format ( Strings . BadColumnCast , column . DataType , typeof ( UInt16 ) ) ) ;
476
496
}
477
-
478
497
}
479
498
}
0 commit comments