-
I am interested in being able to replace the coordinate in a MultiIndex with new values after some mathematical operation. There appears to be some circumstances in which this works and doesn't. I'm aware there is a indexing refactor that is ongoing and not sure what is a bug or isn't so I figured I'd start a discussion instead of an issue. I previously started a similar discussion regarding adding or removing levels here, which was resolved and I'm using that method below. I'm making a test mutindexed array like this:
And want to replace the values in the level 'one' with new coordinates of the same length
This doesn't just work directly giving the following traceback.
I guess my first question is: is there some other operation I should do to accomplish this coordinate reassignment? I have been able to make this work by dropping and re-adding the index, which gives the expected result, but this doesn't seem like it should be necessary
However, this method doesn't work if you have a multiindex with one level, which I suspect is a bug. I'm accomplishing this by just dropping the level 'two' first.
This runs into the same value error:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @aspitarl
Reassigning a coordinate that takes part in a multi-coordinate index indeed requires to drop and rebuild the index since the latter is immutable. It would certainly be possible to do this automatically, but IMHO it is probably better if it is done explicitly. Indexes vs. coordinates are often a source of confusion and handling them separately (as much as possible) in the API would make things clearer. Another reason is that building an index may be costly: it is not straightforward to figure out why updating a coordinate is slow if the index is rebuilt under the hood. Regarding
It looks like a bug indeed. Could you open a new issue, please? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. Keeping things explicit sounds good. Its just difficult to know if I'm missing a more built-in/elegant method or doing something that's not a best practice, which stems from the confusion of indices and coordinates as you mention. I've started an issue at #6959 |
Beta Was this translation helpful? Give feedback.
Hi @aspitarl
Reassigning a coordinate that takes part in a multi-coordinate index indeed requires to drop and rebuild the index since the latter is immutable. It would certainly be possible to do this automatically, but IMHO it is probably better if it is done explicitly. Indexes vs. coordinates are often a source of confusion and handling them separately (as much as possible) in the API would make things clearer. Another reason is that building an i…