-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
read_csv
does not return columns in the order specified by columns
parameter
#13066
Comments
Related to #13040 Happy to accept a fix for this one. |
I want to pick this one up!
in the But I believe fixing it from the rust side would be better agree? |
Yes! If this code path leads to the Rust side, it would have to be fixed there. |
As I noted in the related PR, the offending code seems to be here: polars/crates/polars-io/src/csv/read_impl/mod.rs Lines 227 to 240 in 11c6f9b
|
This should ideally be fixed by making |
Fixing this would actually make selecting and renaming columns during reading much easier, because with cols = ["A", "F", "C", "E", "D", "B"]
cols_new = ["a", "f", "c", "e", "d", "b"]
df = (
pl.scan_csv(logfile)
.select(cols)
.rename({k: v for k, v in zip(cols, cols_new)})
) But this could be much simpler: df = pl.read_csv(logfile, columns=cols, new_columns=cols_new) Unless of course I'm missing something. |
@cbrnr you are not missing anything; that's the intent, it's just a bit messy right now. Furthermore, the order shouldn't matter, i.e. you should be able to do: cols = ["D", "B", "A"] # notice out of order
cols_new = ["d", "b", "a"]
df = pl.read_csv(logfile, columns=cols, new_columns=cols_new) ...but this is currently broken. |
Yes, I know that the column order is currently broken in |
@stinodego was saying this is how it will/should work "under the hood"--meaning you could continue to use |
Yes, this would be great indeed! Meanwhile, I've switched to |
Checks
Reproducible example
Issue description
When the
columns
parameter is specified in order to select out the columns, the order return corresponds to the original frame's order, not the order specified bycolumns
.Related Issues: #11186, #11535.
Expected behavior
Should return requested order.
Installed versions
The text was updated successfully, but these errors were encountered: