huggingface / huggingface/datasets

The `Sequence` class in features do not have "dtype"

Open
#8,002 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
22k
Forks
3.4k
Avg merge
5d 7h
Merged PRs (30d)
17

Description

### Describe the bug

**I'm not sure if this is a bug.**

I see that a `FeatureType` object contains an attribute called `self.dtype` that is not covered when this feature is a `Sequence` or a `List`.

When I try to run a multilabel classification with this example script from the transformers library:

https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_classification.py#L442

I get this error on the linked line:

```shell
AttributeError: 'List' object has no attribute 'dtype'. Did you mean: '_type'?
```

Looking at the check that the script is attempting to perform, could we perhaps add a `self.dtype="list"` attribute for this `FeatureType` 's: `Sequence`, `List`, etc.?

### Steps to reproduce the bug

For example, this code works for me:

```python
from datasets import ClassLabel, Features, Sequence, Value
features = {'text': Value('string'), 'label': ClassLabel(names=['No', 'Yes'])}
print(features["text"].dtype)
print(features["label"].dtype)
```
```output
'string'
'int64'
```

and this code does not work for me:

```python
from datasets import ClassLabel, Features, Sequence, Value
features = {'text': Value('string'), 'label': Sequence(ClassLabel(names=['No', 'Yes']))}
print(features["label"].dtype) # it could be equal to "list"?
```
```output
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'List' object has no attribute 'dtype'. Did you mean: '_type'?
```

### Expected behavior

The attribute `dtype` equal to `"list"` when using objects of type `Sequence`.

```python
from datasets import ClassLabel, Features, Sequence, Value
features = {'text': Value('string'), 'label': Sequence(ClassLabel(names=['No', 'Yes']))}
print(features["label"].dtype)
```
```output
'list'
```

### Environment info

I have installed `datasets==4.5.0`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.