-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
with_context not present for pl.DataFrame #14775
Comments
It makes no difference to me though as its only a matter of calling .lazy() when using .with_context. I am just curious. |
I think That was recently added: I recall reading in one of the previous issues that |
I don't think it should, >>> import polars as pl
>>> ldf1 = pl.LazyFrame({"a": [1, 2, 3]})
>>> ldf2 = pl.LazyFrame({"b": [1, 2, 3, 4]})
>>> ldf1.with_context(ldf2).select(pl.all().sum()).collect()
shape: (1, 2)
┌─────┬─────┐
│ a ┆ b │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 6 ┆ 10 │
└─────┴─────┘ |
oh....I didn't know that. So it was a workaround. If I want to get a mask of different dataframe and directly plot. A = (
pl.DataFrame({
"id":np.arange(1000),
"some_ranodm_strcol":np.random.choice(a=["a","b","c"],size=1000)
})
)
B = (
pl.DataFrame({
"id":np.random.choice(1000,size=500,replace=False),
"some_ranodm_strcol":np.random.choice(a=["a","b","c"],size=500)
})
.sort(by="id")
)
(
A
.lazy()
.with_context(
B.lazy().select(pl.all().suffix("_b"))
)
.select(
pl.col("id"),
pl.col("id").is_in(pl.col("id_b")).cast(pl.Int8).alias("new_col")
)
.collect()
.plot.line(
x="id",
y="new_col"
)
) Is there a different alternative?. I learnt .with_context in udemy's course and its quite helpful when I want to use other dataframes columns to fast visualize(though they didn't teach that) This is why I was curious as to why eager frames don't have .with_context. Its such a unique and novel feature compared to pandas |
Yes exactly. and .with_context should also be extended to pl.DataFrames if theres no downsides to it |
Please use |
I wish I'd atleast know the reason cuz I started(opened) this issue out of curiosity, but thankyou for communicating the changes, now I am sure what to use and what not to. |
|
@cmdlineluser Thankyou! |
Description
Hello polars team,
Big fan. I just observed that lazyframes have the method with_context while eager ones do not.
I just wanted to know reason behind that.
Thankyou!
The text was updated successfully, but these errors were encountered: