Open wukan1986 opened 6 days ago
only change to lazy mode
import polars as pl
import talib as ta
df = pl.DataFrame({"a": [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ]})
a = df.with_columns([
pl.col('a').map_batches(lambda x: pl.DataFrame(ta.MACD(x, 3, 4, 5)).to_struct())
]).with_columns(
pl.col('a').struct[0]
)
print(a)
"""
shape: (11, 2)
┌──────────────────────────────┬──────────┐
│ a ┆ column_0 │
│ --- ┆ --- │
│ struct[3] ┆ f64 │
╞══════════════════════════════╪══════════╡
│ {NaN,NaN,NaN} ┆ NaN │
│ {NaN,NaN,NaN} ┆ NaN │
│ {NaN,NaN,NaN} ┆ NaN │
│ {NaN,NaN,NaN} ┆ NaN │
│ {NaN,NaN,NaN} ┆ NaN │
│ … ┆ … │
│ {NaN,NaN,NaN} ┆ NaN │
│ {0.4676,0.38472,0.08288} ┆ 0.4676 │
│ {0.48056,0.416667,0.063893} ┆ 0.48056 │
│ {0.488336,0.440556,0.04778} ┆ 0.488336 │
│ {0.493002,0.458038,0.034963} ┆ 0.493002 │
└──────────────────────────────┴──────────┘
"""
a = df.lazy().with_columns([
pl.col('a').map_batches(lambda x: pl.DataFrame(ta.MACD(x, 3, 4, 5)).to_struct())
]).with_columns(
pl.col('a').struct[0]
)
print(a.collect())
"""
polars.exceptions.InvalidOperationError: expected 'struct' dtype, got Unknown(Any)
"""
Checks
Reproducible example
Log output
No response
Issue description
return_dtype
can not infer struct inmap_batches
Expected behavior
I hope
return_dtype
can infer structInstalled versions