[Python] ValueError: setting an array element with a sequence in Vaex dataframe

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    I've been given a CSV file from a previous project and I'm supposed to prepare some scripts with Python to plot the value it contains. The dataset in this CSV file holds data from electric and vibration signals. The data I'm interested in is stored at a column, "DecompressedValue", where each row holds a 16.000-elements-long array of float values, which represents a vibration/electric signal.

    I want to use Vaex to exploit its higher performance features, but I found what I think is a bug when processing the signals. I started adapting code which works in Pandas.

    import pandas as pd
    import json
    signal_df = pd.read_csv('csv_test.csv', sep=';')
    # The DecompressedValue column, despite being stored as a regular array, is read a long string, so in order to turn it into an array, json.loads() has to be applied to each value of the column
    signal_df.DecompressedValue = signal_df.DecompressedValue.apply(lambda r: json.loads(r))


    However, when trying to replicate the same functionality in Vaex, even if this code runs correctly, trying to access the dataframe after that produces an error (find vaex_test.csv for testing this code here).

    import vaex

    test = vaex.from_csv('vaex_test.csv', sep=';')
    test['DecompressedValue'] = test['DecompressedValue'].apply(lambda r: json.loads(r))
    test.head()


    This produce a ValueError:

    [12/19/24 12:50:48] ERROR error evaluating: DecompressedValue at rows 0-5 [dataframe.py](file:///C:/Users/user/AppData/Local/anaconda3/envs/py310env/lib/site-packages/vaex/dataframe.py):[4101](file:///C:/Users/user/AppData/Local/anaconda3/envs/py310env/lib/site-packages/vaex/dataframe.py#4101)
    multiprocessing.pool.RemoteTraceback:
    """
    Traceback (most recent call last):
    File
    "c:\Users\user\AppData\Local\anaconda3\envs\py310env\lib\mu
    ltiprocessing\pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
    File
    "c:\Users\user\AppData\Local\anaconda3\envs\py310env\lib\si
    te-packages\vaex\expression.py", line 1629, in _apply
    result = np.array(result)
    ValueError: setting an array element with a sequence. The requested
    array has an inhomogeneous shape after 1 dimensions. The detected
    shape was (5,) + inhomogeneous part.
    """

    Continue reading...

Compartilhe esta Página