Skip to content
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

fix(rust, python): prevent re-ordering of dict keys inside .apply #10172

Merged
merged 1 commit into from
Jul 31, 2023

Conversation

cmdlineluser
Copy link
Contributor

Attempts to fix #10128

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Jul 30, 2023
@@ -54,6 +54,10 @@ fn iterator_to_struct<'a>(
// ]
let mut struct_fields: BTreeMap<&str, Vec<AnyValue>> = BTreeMap::new();

// as a BTreeMap sorts its keys, we also need to track the original
Copy link
Member

@ritchie46 ritchie46 Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use PlIndexMap if insertion order needs to be maintained.

I think the other changes can be reverted after that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks @ritchie46 - my searching did find https://doc.rust-lang.org/stable/nightly-rustc/rustc_data_structures/sorted_map/struct.SortedIndexMultiMap.html but not PlIndexMap

Trying PlIndexMap gives me this back from the compiler, I'm not sure how to proceed.

error[E0599]: the method `par_iter` exists for struct `IndexMap<&str, Vec<AnyValue<'_>>, RandomState>`, but its trait bounds were not satisfied
   --> src/apply/mod.rs:114:14
    |
113 | /             struct_fields
114 | |             .par_iter()
    | |_____________-^^^^^^^^
    |
   ::: /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/indexmap-2.0.0/src/map.rs:81:1
    |
81  |   pub struct IndexMap<K, V, S = RandomState> {
    |   ------------------------------------------ doesn't satisfy `_: IntoParallelRefIterator<'_>`
    |
    = note: the following trait bounds were not satisfied:
            `&indexmap::map::IndexMap<&str, Vec<polars_rs::prelude::AnyValue<'_>>, ahash::RandomState>: polars_rs::export::rayon::iter::IntoParallelIterator`
            which is required by `indexmap::map::IndexMap<&str, Vec<polars_rs::prelude::AnyValue<'_>>, ahash::RandomState>: polars_rs::export::rayon::iter::IntoParallelRefIterator<'_>`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. Then this solution is fine. Thank you! 👍

@ritchie46 ritchie46 merged commit 600c325 into pola-rs:main Jul 31, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Polars apply changing key order in returned dict
2 participants