Skip to content

add support for pyarrow string view in features #7718

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ requirements:
- python
- pip
- numpy >=1.17
- pyarrow >=15.0.0
- pyarrow >=16.0.0
- python-xxhash
- dill
- pandas
Expand All @@ -30,7 +30,7 @@ requirements:
- python
- pip
- numpy >=1.17
- pyarrow >=15.0.0
- pyarrow >=16.0.0
- python-xxhash
- dill
- pandas
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
run: uv pip install --system --upgrade pyarrow huggingface-hub "dill<0.3.9"
- name: Install dependencies (minimum versions)
if: ${{ matrix.deps_versions != 'deps-latest' }}
run: uv pip install --system pyarrow==15.0.0 huggingface-hub==0.24.7 transformers dill==0.3.1.1
run: uv pip install --system pyarrow==16.0.0 huggingface-hub==0.24.7 transformers dill==0.3.1.1
- name: Test with pytest
run: |
python -m pytest -rfExX -m ${{ matrix.test }} -n 2 --dist loadfile -sv ./tests/
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
# We use numpy>=1.17 to have np.random.Generator (Dataset shuffling)
"numpy>=1.17",
# Backend and serialization.
# Minimum 15.0.0 to be able to cast dictionary types to their underlying types
"pyarrow>=15.0.0",
# Minimum 16.0.0 to support string views
"pyarrow>=16.0.0",
# For smart caching dataset processing
"dill>=0.3.0,<0.3.9", # tmp pin until dill has official support for determinism see https://github.com/uqfoundation/dill/issues/19
# For performance gains with apache arrow
Expand Down
7 changes: 7 additions & 0 deletions src/datasets/features/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def _arrow_to_datasets_dtype(arrow_type: pa.DataType) -> str:
return "string"
elif pyarrow.types.is_large_string(arrow_type):
return "large_string"
elif pyarrow.types.is_string_view(arrow_type):
return "string_view"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pa.string_view exists, so in the complementing functionstring_to_arrow("string_view") will return pa.StringView correctly

elif pyarrow.types.is_dictionary(arrow_type):
return _arrow_to_datasets_dtype(arrow_type.value_type)
else:
Expand Down Expand Up @@ -508,6 +510,7 @@ class Value:
- `large_binary`
- `string`
- `large_string`
- `string_view`

Args:
dtype (`str`):
Expand Down Expand Up @@ -548,6 +551,10 @@ def encode_example(self, value):
return float(value)
elif pa.types.is_string(self.pa_type):
return str(value)
elif pa.types.is_large_string(self.pa_type):
return str(value)
elif pa.types.is_string_view(self.pa_type):
return str(value)
else:
return value

Expand Down