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

Dict feature is non-nullable while nested dict feature is #6738

Closed
polinaeterna opened this issue Mar 18, 2024 · 3 comments · Fixed by #6743
Closed

Dict feature is non-nullable while nested dict feature is #6738

polinaeterna opened this issue Mar 18, 2024 · 3 comments · Fixed by #6743
Labels
bug Something isn't working

Comments

@polinaeterna
Copy link
Contributor

When i try to create a Dataset object with None values inside a dict column, like this:

from datasets import Dataset, Features, Value

Dataset.from_dict(
    {
        "dict": [{"a": 0, "b": 0}, None],
    }, features=Features(
        {"dict": {"a": Value("int16"), "b": Value("int16")}}
    )
)

i get ValueError: Got None but expected a dictionary instead.

At the same time, having None in nested dict feature works, for example, this doesn't throw any errors:

from datasets import Dataset, Features, Value, Sequence

dataset = Dataset.from_dict(
    {
        "list_dict": [[{"a": 0, "b": 0}], None],
        "sequence_dict": [[{"a": 0, "b": 0}], None],
    }, features=Features({
        "list_dict": [{"a": Value("int16"), "b": Value("int16")}],
        "sequence_dict": Sequence({"a": Value("int16"), "b": Value("int16")}),
    })
)

Other types of features also seem to be nullable (but I haven't checked all of them).

Version of datasets is the latest atm (2.18.0)

Is this an expected behavior or a bug?

@lhoestq
Copy link
Member

lhoestq commented Mar 19, 2024

It looks like a bug, by default every feature should be nullable.

@polinaeterna polinaeterna added the bug Something isn't working label Mar 19, 2024
@mariosasko
Copy link
Collaborator

I've linked a PR with a fix :)

@polinaeterna
Copy link
Contributor Author

@mariosasko awesome thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants