Skip to content

Commit

Permalink
update snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Sep 14, 2024
1 parent 564f9e5 commit 7c5c61a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/aggregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn vertical_weighted_mean(inputs: &[Series]) -> PolarsResult<Series> {
}
});
let result = numerator / denominator;
Ok(Series::new("", vec![result]))
Ok(Series::new(PlSmallStr::EMPTY, vec![result]))
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ And we can finally move to the actual plugin code:
// #[polars_expr(output_type=Array)]
pub fn point_2d_output(_: &[Field]) -> PolarsResult<Field> {
Ok(Field::new(
"point_2d",
PlSmallStr::from_static("point_2d"),
DataType::Array(Box::new(DataType::Float64), 2),
))
}
Expand Down
1 change: 0 additions & 1 deletion docs/cum_sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ fn cum_sum(inputs: &[Series]) -> PolarsResult<Series> {
}
})
.collect_trusted();
let out: Int64Chunked = out.with_name(ca.name());
Ok(out.into_series())
}
```
Expand Down
3 changes: 1 addition & 2 deletions docs/life_pt1.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ fn life_step(inputs: &[Series]) -> PolarsResult<Series> {

let len = lf.len();

let mut out: Int64Chunked = mid
let out: Int64Chunked = mid
.iter()
.enumerate()
.map(|(idx, val)| {
Expand Down Expand Up @@ -297,7 +297,6 @@ fn life_step(inputs: &[Series]) -> PolarsResult<Series> {
})
})
.collect_trusted();
out.rename(ca_curr.name());
Ok(out.into_series())
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
(Some(lhs), Some(rhs)) => f(&lhs, &rhs),
_ => None,
})
.collect_ca(lhs.name())
.collect_ca(PlSmallStr::EMPTY)
}
}
```
Expand Down
6 changes: 3 additions & 3 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(input_fields[0].name(), DataType::List(Box::new(IDX_DTYPE)));
fn list_idx_dtype(_input_fields: &[Field]) -> PolarsResult<Field> {
let field = Field::new(PlSmallStr::EMPTY, DataType::List(Box::new(IDX_DTYPE)));
Ok(field.clone())
}

Expand All @@ -57,7 +57,7 @@ fn non_zero_indices(inputs: &[Series]) -> PolarsResult<Series> {
.enumerate()
.filter(|(_idx, opt_val)| opt_val != &Some(0))
.map(|(idx, _opt_val)| Some(idx as IdxSize))
.collect_ca("");
.collect_ca(PlSmallStr::EMPTY);
out.into_series()
});
Ok(out.into_series())
Expand Down
13 changes: 6 additions & 7 deletions docs/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ Then, we need to get the schema right.
```Rust
fn shifted_struct(input_fields: &[Field]) -> PolarsResult<Field> {
let field = &input_fields[0];
match field.data_type() {
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(), fld.data_type().clone()))
.map(|(fld, name)| Field::new(name.name().clone(), fld.dtype().clone()))
.collect::<Vec<_>>();
fields.push(field_0);
Ok(Field::new(&name, DataType::Struct(fields)))
Ok(Field::new(PlSmallStr::EMPTY, DataType::Struct(fields)))
}
_ => unreachable!(),
}
Expand All @@ -68,18 +67,18 @@ 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());
field_0.rename(fields[fields.len() - 1].name()).clone();
let mut fields = fields[1..]
.iter()
.zip(fields[..fields.len() - 1].iter())
.map(|(s, name)| {
let mut s = s.clone();
s.rename(name.name());
s.rename(name.name().clone());
s
})
.collect::<Vec<_>>();
fields.push(field_0);
StructChunked::from_series(struct_.name(), &fields).map(|ca| ca.into_series())
StructChunked::from_series(PlSmallStr::EMPTY, &fields).map(|ca| ca.into_series())
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/vec_of_option.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ where
out.into(),
Some(validity.into()),
);
ChunkedArray::with_chunk(chunked_arr.name(), array)
ChunkedArray::with_chunk(PlSmallStr::EMPTY, array)
} else {
ChunkedArray::from_vec(chunked_arr.name(), out)
}
Expand Down Expand Up @@ -164,7 +164,7 @@ if first != 0 || last != chunked_arr.len() {
out.into(),
Some(validity.into()),
);
ChunkedArray::with_chunk(chunked_arr.name(), array)
ChunkedArray::with_chunk(PlSmallStr::EMPTY, array)
} else {
ChunkedArray::from_vec(chunked_arr.name(), out)
}
Expand Down

0 comments on commit 7c5c61a

Please sign in to comment.