Closed dmitrii-doronin closed 5 days ago
Just checked the source code, it is easy to solve if we use OrderedCollections,
I'm not sure whether to add a new dependency for this feature, but from an implementation point of view it will definitely reduce the code complexity. Although I think this can actually be solved using Vector, the readability of the code will definitely decrease. I think adding new dependencies is a better approach.
(I'm still thinking about it. You don't need to take the time to view the source code and comment, thanks!)
I have completed a prototype implementation using OrderCollection, and obviously the order of cols
actually depends on the order of to_flatten()
return, however to_flatten()
returns Dict
, and there is no guarantee of the order in which the elements are taken out.
So starting from this change, to_flatten()
needs to return OrderedDict
.
And it is impossible to save the field order in to_csv()
before execute to_flatten()
, we still need to flatten the structure to get column name, so we cannot bypass the call of to_flatten()
Preserve headers order by default in CSV serialisation
Description
Current implementation does not preserve order of fields in structs. This confuses users and should be fixed.
Tasks