Skip to content

Commit 0421944

Browse files
committed
Revert "Improved dicts_to_rows"
This reverts commit 5d035ae.
1 parent cf173e6 commit 0421944

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

ext/polars/src/dataframe/construction.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use magnus::{RArray, RHash, RString, Ruby, Symbol, Value, prelude::*, r_hash::ForEach};
1+
use magnus::{RArray, RHash, Ruby, Symbol, Value, prelude::*, r_hash::ForEach};
22
use polars::frame::row::{Row, rows_to_schema_supertypes, rows_to_supertypes};
33
use polars::prelude::*;
44

@@ -128,19 +128,13 @@ fn dicts_to_rows<'a>(data: &Value, names: &'a [String], _strict: bool) -> RbResu
128128
let ruby = Ruby::get_with(*data);
129129
let (data, len) = get_rbseq(*data)?;
130130
let mut rows = Vec::with_capacity(len);
131-
132-
// pre-convert keys/names so we don't repeatedly create them in the loop
133-
let rb_keys: Vec<(RString, Symbol)> = names
134-
.iter()
135-
.map(|k| (ruby.str_new(k), ruby.to_symbol(k)))
136-
.collect();
137-
138131
for d in data.into_iter() {
139132
let d = RHash::try_convert(d)?;
140133

141134
let mut row = Vec::with_capacity(names.len());
142-
for (k, k2) in &rb_keys {
143-
let val = match d.get(*k).or_else(|| d.get(*k2)) {
135+
for k in names.iter() {
136+
// TODO improve performance
137+
let val = match d.get(k.clone()).or_else(|| d.get(ruby.to_symbol(k))) {
144138
None => AnyValue::Null,
145139
Some(val) => Wrap::<AnyValue>::try_convert(val)?.0,
146140
};

0 commit comments

Comments
 (0)