-
Notifications
You must be signed in to change notification settings - Fork 125
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
Support Series.from_list([1, 2, 3], dtype: :null)
#806
Comments
cc @lkarthee in case you want to take a look at this one too :) |
Was just testing this exact thing out in livebook. 👍 |
FYI, we may need to use use polars::prelude::*;
fn main() {
let s = Series::new_null("a", 0);
println!("dtype is: {}", &s.dtype())
} |
I fixed null -> any conversion needs to be added. I have noticed that:
|
Yes, but I'm changing this in #794
Probably it's easier to revisit after I finish that work, yeah. |
One question about type casting of nulls when concat rows. In Polars, concat works as:
Should we support both cases without throwing error by handling casting if needed or should we only support Type ++ Null ? I am trying to fix Series.concat for Type ++ Null as it is failing. |
There is a chance that Null + Types not working is a Polars bug, so I would take a look and perhaps do a report there. If that’s the case, I would write your code as if both styles are support and then let Polars blow up (until it is fixed). |
My line of thought is Type can have value nil, while concatenation why can't it be treated a set of rows having nil values being added ? Null ++ Type failure does not make sense for me particularly if a cast can solve it. I might be missing something. Please share your thoughts on this. Edit: did not see Jose reply. Posted this message. |
I'd also be ok with a cast. We had to do something similar when Polars supported |
// if returns
// `Ok(true)`: can extend, but must cast
// `Ok(false)`: can extend as is
// Error: cannot extend.
pub(crate) fn can_extend_dtype(left: &DataType, right: &DataType) -> PolarsResult<bool> {
match(left, right) {
...
(DataType::Null, DataType::Null) => Ok(false),
// Other way around we don't allow because we keep left dtype as is.
// We don't go to supertype, and we certainly don't want to cast self to null type.
(_, DataType::Null) => Ok(true),
(l, r) => {
polars_ensure!(l == r, SchemaMismatch: "cannot extend/append {:?} with {:?}", left, right); |
Polars allows only concat of series with same data type. They don't get into type promotion. Only exception is Type ++ Null. > f32 = pl.Series([1, 2, 3], dtype=pl.Float32)
> s16 = pl.Series([1, 2, 3], dtype=pl.Int16)
> s8= pl.Series([1, 2, 3], dtype=pl.Int8)
> f32.append(s8)
SchemaError: cannot extend/append Float32 with Int8
> s16.append(s8)
SchemaError: cannot extend/append Int16 with Int8 We have some kind of type promotion to float for numeric types in |
Good find. So apparently Polars logic is that it must preserve the type on the left side, rather than trying to find a magic type that satisfies both sides. I'd say that's a sane we choose to mimic if we want to. Overall, we have to choose between:
Any opinions? |
#812 about Null ++ Type and Type ++ Null can be done. We can cast to a higher type if there is no loss of information. |
Thank you, I will close this one, we can the discussion in the PR. :) |
We should also discuss if the default for a list of nils should still be
:f64
or if we should swap it to:null
:The text was updated successfully, but these errors were encountered: