Dexter Antonio
11/30/2024, 6:45 PMimage_id column and a predictions column in s3. The image_id column is of type Utf8 and the predictions column is of type FixedSizeList[Float64; 1000] I want to group by image_id and take the mean value of item 150 in predictions column.
╭────────────────────────────────┬────────────────────────────────╮
│ image_id ┆ predictions │
│ --- ┆ --- │
│ Utf8 ┆ FixedSizeList[Float64; 1000] │
╞════════════════════════════════╪════════════════════════════════╡
I'd like to explicitly access a single element in the FixedSizeList during aggregation, but I cannot find any documentation of the methods of a column full of datatypes FixedSizeList. The only way that I have found to select an element is to first convert the FixedSizedList to a Python list and then to a list datatype followed by using the get method. This blows up the memory of the pipeline. Ideally, I would like to call a method directly on the column object that selects a single element from FixedSizeList. Does anyone have any tips on how to do this?
Working attempt, which blows up memory
df3 = (
df2.select(col("image_id"), col("predictions"))
.with_column(
"cool_channel",
col("predictions").cast(daft.DataType.python()).cast(daft.DataType.list(daft.DataType.float64())).list.get(150)
)
.groupby('image_id').agg(col("cool_channel").mean().alias("mean_channel"))
)
Ideal solution
df3 = (
df2.select(col("image_id"), col("predictions"))
.with_column(
"cool_channel",
col("predictions").pluck(150) # method does not exist
)
.groupby('image_id').agg(col("cool_channel").mean().alias("mean_channel"))
)
Can someone point me to some more documentation of FixedSizeLists or any solution to this issue?jay
11/30/2024, 6:57 PM.list.get expression?jay
11/30/2024, 6:57 PMcol("predictions").list.get(150)jay
11/30/2024, 6:59 PMDexter Antonio
11/30/2024, 7:00 PM>>> df3 = (
... df2.select(col("image_id"), col("predictions"))
... .with_column(
... "cool_channel",
... col("predictions").list.get(150)
... )
... .groupby('image_id').agg(col("cool_channel").mean().alias("mean_channel"))
... ).show(1)
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/api_annotations.py", line 26, in _wrap
return timed_method(*args, **kwargs)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/analytics.py", line 199, in tracked_method
result = method(*args, **kwargs)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/dataframe/dataframe.py", line 1473, in with_column
return self.with_columns({column_name: expr})
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/api_annotations.py", line 26, in _wrap
return timed_method(*args, **kwargs)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/analytics.py", line 199, in tracked_method
result = method(*args, **kwargs)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/dataframe/dataframe.py", line 1520, in with_columns
builder = self._builder.with_columns(new_columns)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/logical/builder.py", line 159, in with_columns
builder = self._builder.with_columns(column_pyexprs)
daft.exceptions.DaftCoreException: DaftError::External Unable to create logical plan node.
Due to: DaftError::ValueError Column "predictions" with dtype FixedSizeList[Float64; 1000] cannot be exploded, must be a List or FixedSizeList column.Dexter Antonio
11/30/2024, 7:01 PMDue to: DaftError::ValueError Column "predictions" with dtype FixedSizeList[Float64; 1000] cannot be exploded, must be a List or FixedSizeList column.Dexter Antonio
11/30/2024, 7:02 PM.list.get methods but with something else 🤔.jay
11/30/2024, 7:03 PMDexter Antonio
11/30/2024, 7:03 PM$ uv pip freeze | grep getdaft
getdaft==0.3.14jay
11/30/2024, 7:09 PMFixedSizeList[Float64; 1000] type, but the code should never match into that error statement.
Could you try running this code for me? It runs perfectly on my machine, but I wonder if your installation of Daft would error out:
import daft
df = daft.from_pydict({"foo": [[0.1, 0.2], [0.1, 0.2]]})
df = df.with_column(
"foo",
df["foo"].cast(daft.DataType.fixed_size_list(daft.DataType.float64(), 2)),
)
df = df.with_column("x", df["foo"].list.get(0))
df.collect()Dexter Antonio
11/30/2024, 7:10 PM>>> import daft
>>>
>>> df = daft.from_pydict({"foo": [[0.1, 0.2], [0.1, 0.2]]})
",
df["foo"].cast(daft.DataType.fixed_size_list(daft.DataType.float64(), 2)),
)
df = df.with_column("x", df["foo"].list.get(0))
df.collect()
>>> df = df.with_column(
... "foo",
... df["foo"].cast(daft.DataType.fixed_size_list(daft.DataType.float64(), 2)),
... )
>>> df = df.with_column("x", df["foo"].list.get(0))
>>> df.collect()
╭───────────────────────────┬─────────╮
│ foo ┆ x │
│ --- ┆ --- │
│ FixedSizeList[Float64; 2] ┆ Float64 │
╞═══════════════════════════╪═════════╡
│ [0.1, 0.2] ┆ 0.1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ [0.1, 0.2] ┆ 0.1 │
╰───────────────────────────┴─────────╯
(Showing first 2 of 2 rows)
>>>Dexter Antonio
11/30/2024, 7:11 PMjay
11/30/2024, 7:12 PMjay
11/30/2024, 7:12 PMDexter Antonio
11/30/2024, 7:14 PMjay
11/30/2024, 7:14 PMpredictions columnDexter Antonio
11/30/2024, 7:15 PMjay
11/30/2024, 7:21 PMDexter Antonio
11/30/2024, 7:31 PMimport daft
from daft import col
df2 = daft.read_parquet("test3.parquet")
df3 = (
df2.select(col("image_id"), col("predictions"))
.with_column(
"cool_channel",
col("predictions").list.get(150)
)
.groupby('image_id').agg(col("cool_channel").mean().alias("mean_channel"))
).show(1)
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/api_annotations.py", line 26, in _wrap
return timed_method(*args, **kwargs)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/analytics.py", line 199, in tracked_method
result = method(*args, **kwargs)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/dataframe/dataframe.py", line 1473, in with_column
return self.with_columns({column_name: expr})
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/api_annotations.py", line 26, in _wrap
return timed_method(*args, **kwargs)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/analytics.py", line 199, in tracked_method
result = method(*args, **kwargs)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/dataframe/dataframe.py", line 1520, in with_columns
builder = self._builder.with_columns(new_columns)
File "/root/workspaces/noetik-analysis/.venv/lib/python3.10/site-packages/daft/logical/builder.py", line 159, in with_columns
builder = self._builder.with_columns(column_pyexprs)
daft.exceptions.DaftCoreException: DaftError::External Unable to create logical plan node.
Due to: DaftError::ValueError Column "predictions" with dtype FixedSizeList[Float64; 1000] cannot be exploded, must be a List or FixedSizeList column.
If I create test.parquet with pandas, then the error is resolved. The problem could lie in how daft is writing parquet column metadata.Dexter Antonio
11/30/2024, 7:31 PMjay
11/30/2024, 7:32 PMDexter Antonio
11/30/2024, 7:32 PMjay
11/30/2024, 7:36 PMjay
11/30/2024, 7:36 PMDexter Antonio
11/30/2024, 7:42 PMjay
11/30/2024, 7:48 PMjay
11/30/2024, 7:48 PMDexter Antonio
11/30/2024, 7:50 PM