You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Microsoft.Data.Analysis DataFrameColumns.SetName method is weird #6129
Looks like the columns themselves don't have a reference to the parent DataFrame, hence this behavior. I think the way to fix this would be to have the column have a reference to the DataFrame so it can perform the update as you point out. I dont think it would be a big change. @luisquintanilla
Ok, the other option (or we could do both), is that dataFrame.Columns does have a SetColumnName method as well, it just for some reason requires you to pass in the whole column SetColumnName(DataFrameColumn column, string newName). We could just overload that method to just take the name of the current column and the name you want to set it to SetColumnName(string curName, string newName). Then you could just call dataFrame.Columns.SetColumnName("cur", "new");. Thoughts?
Note that, because SetName has a default value of null for the DataFrame parameter, if a user tries dataFrame["oldColumnName"]("newColumnName"), not only will this fail, but it will also not throw an exception, resulting in a bug that is hard to catch.
Activity
michaelgsharp commentedon Mar 18, 2022
Looks like the columns themselves don't have a reference to the parent DataFrame, hence this behavior. I think the way to fix this would be to have the column have a reference to the DataFrame so it can perform the update as you point out. I dont think it would be a big change. @luisquintanilla
michaelgsharp commentedon Mar 18, 2022
Ok, the other option (or we could do both), is that
dataFrame.Columnsdoes have aSetColumnNamemethod as well, it just for some reason requires you to pass in the whole columnSetColumnName(DataFrameColumn column, string newName). We could just overload that method to just take the name of the current column and the name you want to set it toSetColumnName(string curName, string newName). Then you could just calldataFrame.Columns.SetColumnName("cur", "new");. Thoughts?luisquintanilla commentedon Mar 29, 2022
Thanks for reporting this issue @olavt.
@michaelgsharp Thanks for looking into this and providing those solutions. Tracking this issue as part of DataFrame improvements.
chrisxfire commentedon Aug 10, 2022
Note that, because
SetNamehas a default value ofnullfor theDataFrameparameter, if a user triesdataFrame["oldColumnName"]("newColumnName"), not only will this fail, but it will also not throw an exception, resulting in a bug that is hard to catch.You can guess who the user is... 😀