-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
with_columns(dict)
silently ignores dictionary values
#17879
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
Comments
with_columns(dict)
fail silently if keys exists as columnwith_columns(dict)
fail silently if key exists as column
I don't understand this issue? Can you explain more elaborately? |
It seems the issue is that Polars will "iterate" a dict, so you get just the So the the examples effectively become: pl.DataFrame({"a": 1}).with_columns(["a"])
pl.DataFrame({"a": 1}).with_columns(["not_exist"])
# ColumnNotFoundError: not_exist |
The issue is the behavior of with_columns if you give a dictionary as input . |
This is just a side-effect of a dictionary being an Iterable, I don't believe using a dictionary is intended. >>> list({1: 2, 3: 4})
[1, 3] |
I think we can just fix this by requiring a Edit: I don't think Sequence would work, we need generators to work here. |
Just ran into this as well. It would be great for this to error rather than fail silently. |
I no longer think that this should raise. This is just user error, and the fact that python yields the keys when a dictionary is iterated is simply something to watch out for. |
Oh, I hadn't realised that |
with_columns(dict)
fail silently if key exists as columnwith_columns(dict)
silently ignores dictionary values
We should just raise an error when a dictionary input is given It's possible to correctly use a dictionary for >>> data = {"a": pl.col("a") * 2}
>>> pl.select(a=1).with_columns(**data)
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ i32 │
╞═════╡
│ 2 │
└─────┘
>>> pl.select(a=1).with_columns(expr.alias(name) for name, expr in data.items())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ i32 │
╞═════╡
│ 2 │
└─────┘ |
Hi team, can I take up this issue and come up with a fix for it? |
Feel free to |
Checks
Reproducible example
Log output
No response
Issue description
The code I wrote is not correct I forgot the
**
to unpack the dictionary. This exemple is just to show how this bug (?) can happen and can be hard to pinpoint.Expected behavior
Nevertheless, I think it should raise here. it raises in this case for exemple
df.with_columns({"not_exist": 1})
Installed versions
The text was updated successfully, but these errors were encountered: