Skip to content

Commit

Permalink
add debugging notebook and vstack
Browse files Browse the repository at this point in the history
  • Loading branch information
kolibril13 committed Jan 8, 2025
1 parent b389f27 commit 173daea
Show file tree
Hide file tree
Showing 2 changed files with 476 additions and 2 deletions.
46 changes: 44 additions & 2 deletions csv_importer/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,51 @@ def polars_df_to_bob(df: pl.DataFrame, name: str) -> db.BlenderObject:

for col in df.columns:
col_dtype = df[col].dtype
if col_dtype in [pl.Utf8]:
if col_dtype in [pl.Utf8]: # skip strings
continue
data = df[col].to_numpy()
data = np.vstack(df[col].to_numpy())
bob.store_named_attribute(data, col)

return bob

"""
Converts a Polars DataFrame into a Blender object (bob) and stores its columns as named attributes.
`np.vstack` is used to ensure that 3D vectors are properly porcessed.
Example:
import polars as pl
import numpy as np
import databpy as db
# Create a DataFrame
df = pl.DataFrame({
"Star": [
[58.2136, 91.8819, 0.0],
[58.1961, 92.215, 0.0]
],
"Is_Visible": [True, False],
"Intensity": [10, 20],
})
# convert "Star" column to a NumPy array (won't work in databpy)
df["Star"].to_numpy()
# Output:
# array([array([58.2136, 91.8819, 0. ]),
# array([58.1961, 92.215 , 0. ])], dtype=object)
# Use np.vstack to stack the arrays vertically (this will work in databpy)
np.vstack(df["Star"].to_numpy())
# Output:
# array([[58.2136, 91.8819, 0. ],
# [58.1961, 92.215 , 0. ]])
vertices = np.zeros((len(df), 3), dtype=np.float32)
bob = db.create_bob(vertices, name="DataWithVector")
for col in df.columns:
data = np.vstack(df[col].to_numpy())
bob.store_named_attribute(data, col)
"""
Loading

0 comments on commit 173daea

Please sign in to comment.