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

Raise a friendly message when a str is provided to TensorFrame(col_names_dict) instead of a list[str] #469

Merged
merged 1 commit into from
Dec 7, 2024

Conversation

akihironitta
Copy link
Member

@akihironitta akihironitta commented Dec 7, 2024

Repro

import torch
import torch_frame
from torch_frame.data import TensorFrame

feat_dict = {torch_frame.categorical: torch.randint(0, 3, size=(10, 1))}
col_names_dict = {torch_frame.categorical: 'cat_1'}
TensorFrame(feat_dict, col_names_dict)

Before this PR

Traceback (most recent call last):
  File "/home/aki/work/github.com/kumo-ai/kumo/../../akihironitta/gist/test.py", line 7, in <module>
    TensorFrame(feat_dict, col_names_dict)
  File "/home/aki/miniconda3/envs/kumo/lib/python3.10/site-packages/torch_frame/data/tensor_frame.py", line 78, in __init__
    self.validate()
  File "/home/aki/miniconda3/envs/kumo/lib/python3.10/site-packages/torch_frame/data/tensor_frame.py", line 113, in validate
    raise ValueError(
ValueError: The expected number of columns for categorical feature is 5, which does not align with the column dimensionality of feat_dict[categorical] (got 1)

After this PR

Traceback (most recent call last):
  File "/home/aki/work/github.com/pyg-team/pytorch-frame/../../akihironitta/gist/test.py", line 7, in <module>
    TensorFrame(feat_dict, col_names_dict)
  File "/home/aki/work/github.com/pyg-team/pytorch-frame/torch_frame/data/tensor_frame.py", line 78, in __init__
    self.validate()
  File "/home/aki/work/github.com/pyg-team/pytorch-frame/torch_frame/data/tensor_frame.py", line 100, in validate
    raise ValueError(
ValueError: col_names_dict[categorical] must be a list of column names.

@akihironitta akihironitta self-assigned this Dec 7, 2024
@github-actions github-actions bot added the data label Dec 7, 2024
@akihironitta akihironitta enabled auto-merge (squash) December 7, 2024 00:49
@akihironitta akihironitta disabled auto-merge December 7, 2024 00:49
@akihironitta akihironitta merged commit e7a6474 into master Dec 7, 2024
16 of 17 checks passed
@akihironitta akihironitta deleted the aki/tf-validate branch December 7, 2024 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant