Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add debugging notebook and vstack #15

Merged
merged 1 commit into from
Jan 8, 2025
Merged

add debugging notebook and vstack #15

merged 1 commit into from
Jan 8, 2025

Conversation

kolibril13
Copy link
Owner

@kolibril13 kolibril13 commented Jan 8, 2025

using np.vstack will bring the dataframe in the right format for further processing:

import polars as pl
import numpy as np

# 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)

EDIT : More context on Discord https://discord.com/channels/940526858800336936/1298945598728306720/1326155049033924650

@kolibril13 kolibril13 merged commit ff7c07f into main Jan 8, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant