I would like to call the following function ( works fine with pandas) with a polars series..
import pywt
def lowpassfilter(signal, thresh = 0.63, wavelet="db4"):
thresh = thresh*np.nanmax(signal)
coeff = pywt.wavedec(signal, wavelet, mode="per" )
coeff[1:] = (pywt.threshold(i, value=thresh, mode="soft" ) for i in coeff[1:])
reconstructed_signal = pywt.waverec(coeff, wavelet, mode="per" )
return reconstructed_signal
i have tried the following:
df = df.with_columns(pl.struct('close').map(lowpassfilter).alias('wavelet')
and i get a weird array "value error, buffer source aray is read only"
could someone help me, and explain how to call the fuction correctly and what i am doing wrong..
many thanks,
So telling what exactly you are doing wrong is a little bit hard without data, but maybe this example is helping you further. So assuming your column "close" is a list.
Furthermore adapt your function to return a polars series.