In pandas it is possible to broadcast a single value to an entire column or even a slice:
frame.loc[start_index:stop_index, 'a'] = frame.loc[some_row_index, 'a']
that is, a single value being broadcast to a Series.
I tried something similar with polars by doing
frame = frame.with_column(
pl.when(
pl.col("Time").is_between(datetime(2022, 4, 21), datetime(2022, 4, 23))
)
.then(
pl.lit(
frame.filter(pl.col("Time") == datetime(2022, 4, 20)).select(
"col"
)
)
)
.otherwise(pl.col("col"))
.alias("col")
)
but I get the following error:
ValueError: could not convert value 'shape: (1, 1)\n┌────────┐\n│ col │\n│ --- │\n│ i64 │\n╞════════╡\n│ 14 │\n└────────┘' as a Literal
If i just use an integer like pl.lit(6) in the assignment it works fine though. How can i broadcast a single cell value to a column or a slice of a column?
Edit: Ok, so apparently indexing into the shape(1,1) DataFrame like so
frame.filter(pl.col("Time") == datetime(2022, 4, 20)).select("col")[0,0]
and casting the result to a literal asf. works but given that the documentation is rather verbose about not using square bracket notation, is there perhaps a better way?