Skip to content

Commit

Permalink
Merge pull request #50 from MarcoGorelli/preserve-name-for-field
Browse files Browse the repository at this point in the history
preserve name in lazy schema tests
  • Loading branch information
MarcoGorelli authored Sep 14, 2024
2 parents a93186d + 5f57a55 commit 93eeb7a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/lists_in_lists_out.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ a function to each element of a List Series. In this case, we just want to find
elements, so we'll do:

```rust
fn list_idx_dtype(_input_fields: &[Field]) -> PolarsResult<Field> {
let field = Field::new(PlSmallStr::EMPTY, DataType::List(Box::new(IDX_DTYPE)));
fn list_idx_dtype(input_fields: &[Field]) -> PolarsResult<Field> {
let field = Field::new(input_fields[0].name.clone(), DataType::List(Box::new(IDX_DTYPE)));
Ok(field.clone())
}

Expand Down
8 changes: 5 additions & 3 deletions docs/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ fn shifted_struct(input_fields: &[Field]) -> PolarsResult<Field> {
match field.dtype() {
DataType::Struct(fields) => {
let mut field_0 = fields[0].clone();
let name = field_0.name.clone();
field_0.set_name(fields[fields.len() - 1].name().clone());
let mut fields = fields[1..]
.iter()
.zip(fields[0..fields.len() - 1].iter())
.map(|(fld, name)| Field::new(name.name().clone(), fld.dtype().clone()))
.collect::<Vec<_>>();
fields.push(field_0);
Ok(Field::new(PlSmallStr::EMPTY, DataType::Struct(fields)))
Ok(Field::new(name, DataType::Struct(fields)))
}
_ => unreachable!(),
}
Expand All @@ -67,7 +68,8 @@ fn shift_struct(inputs: &[Series]) -> PolarsResult<Series> {
return Ok(inputs[0].clone());
}
let mut field_0 = fields[0].clone();
field_0.rename(fields[fields.len() - 1].name()).clone();
let name = field_0.name().clone();
field_0.rename(fields[fields.len() - 1].name().clone());
let mut fields = fields[1..]
.iter()
.zip(fields[..fields.len() - 1].iter())
Expand All @@ -78,7 +80,7 @@ fn shift_struct(inputs: &[Series]) -> PolarsResult<Series> {
})
.collect::<Vec<_>>();
fields.push(field_0);
StructChunked::from_series(PlSmallStr::EMPTY, &fields).map(|ca| ca.into_series())
StructChunked::from_series(name, &fields).map(|ca| ca.into_series())
}
```

Expand Down
10 changes: 6 additions & 4 deletions src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,15 @@ fn shifted_struct(input_fields: &[Field]) -> PolarsResult<Field> {
match field.dtype() {
DataType::Struct(fields) => {
let mut field_0 = fields[0].clone();
let name = field_0.name.clone();
field_0.set_name(fields[fields.len() - 1].name().clone());
let mut fields = fields[1..]
.iter()
.zip(fields[0..fields.len() - 1].iter())
.map(|(fld, name)| Field::new(name.name().clone(), fld.dtype().clone()))
.collect::<Vec<_>>();
fields.push(field_0);
Ok(Field::new(PlSmallStr::EMPTY, DataType::Struct(fields)))
Ok(Field::new(name, DataType::Struct(fields)))
},
_ => unreachable!(),
}
Expand All @@ -262,6 +263,7 @@ fn shift_struct(inputs: &[Series]) -> PolarsResult<Series> {
return Ok(inputs[0].clone());
}
let mut field_0 = fields[0].clone();
let name = field_0.name().clone();
field_0.rename(fields[fields.len() - 1].name().clone());
let mut fields = fields[1..]
.iter()
Expand All @@ -273,7 +275,7 @@ fn shift_struct(inputs: &[Series]) -> PolarsResult<Series> {
})
.collect::<Vec<_>>();
fields.push(field_0);
StructChunked::from_series(PlSmallStr::EMPTY, &fields).map(|ca| ca.into_series())
StructChunked::from_series(name, &fields).map(|ca| ca.into_series())
}

use reverse_geocoder::ReverseGeocoder;
Expand All @@ -290,8 +292,8 @@ fn reverse_geocode(inputs: &[Series]) -> PolarsResult<Series> {
Ok(out.into_series())
}

fn list_idx_dtype(_input_fields: &[Field]) -> PolarsResult<Field> {
let field = Field::new(PlSmallStr::EMPTY, DataType::List(Box::new(IDX_DTYPE)));
fn list_idx_dtype(input_fields: &[Field]) -> PolarsResult<Field> {
let field = Field::new(input_fields[0].name.clone(), DataType::List(Box::new(IDX_DTYPE)));
Ok(field.clone())
}

Expand Down

0 comments on commit 93eeb7a

Please sign in to comment.