Open stinodego opened 1 year ago
A lit([1, 2, 3])
is not aSeries
of List<i64>
, but a Series
of i64
.
To create a list literal, you must have the same nesting as we have in a list lit([[1, 2, 3]])
. Similar to how we create lists in our series constructor.
There is amiguity as you can create a Series
literal with literal as well. This is done with is_in
a lot.
I agree that it might be easier if we would consider that a list, but then we need to see what that breaks.
I am not sure a tuple should be an array though. : thinking:
I am not sure a tuple should be an array though
From the python perspective a tuple is merely an immutable list so, however they behave, they should probably behave the same 🤷
To create a list literal, you must have the same nesting as we have in a list
lit([[1, 2, 3]])
. Similar to how we create lists in our series constructor.
The input to lit
should be a single element of the data in a Series constructor.
lit(1)
gives a column filled with the value 1
(int type)lit([1, 2])
gives a column filled with the value [1, 2]
(list of ints type)lit([[1, 2]])
gives a column filled with the value [[1, 2]]
(list of list of ints type)The first one is already correct, but the second and third are currently off. They are interpreted to be Series and that leads to different (unexpected) results.
There is amiguity as you can create a
Series
literal with literal as well. This is done withis_in
a lot.
We can keep the behaviour for lit(Series)
for now. Changing that would indeed be a bigger breaking change.
Although I am not sure this makes sense either. In my mind, we have three types of expression columns:
col("a")
lit(1)
lit(Series([1,2,3]))
Making lit
responsible for both 2 and 3 makes things a little confusing. You could argue 3 should create a list-of-ints type literal.
I am not sure a tuple should be an array though
A tuple is Python's standard fixed size collection, so I think it makes at least some amount of sense. But I'm open to alternatives.
@ritchie46 what is the equivalent recipe for creating a list literal for the Rust API currently?
update: got it!:
let inner: Series = some_vec.iter().collect();
let cont = AnyValue::List(inner);
let list: Series = Series::from_any_values_and_dtype("data", &[cont], &DataType::List(Box::new(DataType::Float32)), true).unwrap();
lf.with_column(lit(list).alias("y"))
@ritchie46 Is there currently a less verbose equivalent for creating a list literal on Rust? Or is the @evbo example the most succinct?
The behaviour of the
lit
expression is questionable when trying to create complex types (List
,Array
,Struct
).Consider the following behavior:
I would instead expect the following:
Is there a reason for the existing list behaviour? It seems very confusing.
If the new behaviour is acceptable, I'll see if I can implement this.