Closed timloose closed 4 years ago
sort_index
is really just a wrapper around the pandas functionality and manipulates the underlying DataFrame directly. You could use zmat._frame.sort_index
instead to get the same result.
Since the index is changed without modifying the ['b', 'a', 'd']
columns you could get up with an undefined Z-matrix, so I definetely don't want to return a Zmat instance.
If you want to sort the index and rename ['b', 'a', 'd']
columns accordingly I would use something along
zmat.change_numbering(sorted(zmat.index))
This will return a valid Zmat.
PS:
With the experience I have now, I would never make this method public, because it breaks encapsulation very hard. Honestly I was just too lazy to type zmat._frame.sort_index
everytime when I wanted to sort the index and did not think about the impact.
Calling it has the same implications as manipulating _frame
directly, you have to know, what you are doing and break the abstraction layer.
Okay, thanks for the in depth response!
Code Sample, a copy-pastable example if possible
Problem description
Above code returns: <class 'chemcoord.internal_coordinates.zmat_class_main.Zmat'> <class 'pandas.core.frame.DataFrame'>
This is not ideal, as you cannot use a sorted zmat object without re-making it a zmat.
Expected Output
<class 'chemcoord.internal_coordinates.zmat_class_main.Zmat'> <class 'chemcoord.internal_coordinates.zmat_class_main.Zmat'>
Output of
cc.show_versions()