-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(python): lance write huggingface dataset directly (#1882)
Be able to directly write a huggingface dataset
- Loading branch information
Showing
6 changed files
with
86 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Lance ❤️ HuggingFace | ||
-------------------- | ||
|
||
The HuggingFace Hub has become the go to place for ML practitioners to find pre-trained models and useful datasets. | ||
|
||
HuggingFace datasets can be written directly into Lance format by using the | ||
:meth:`lance.write_dataset` method. You can write the entire dataset or a particular split. For example: | ||
|
||
|
||
.. code-block:: python | ||
# Huggingface datasets | ||
import datasets | ||
import lance | ||
lance.write_dataset(datasets.load_dataset( | ||
"poloclub/diffusiondb", split="train[:10]", | ||
), "diffusiondb_train.lance") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ Integrations | |
|
||
.. toctree:: | ||
|
||
Huggingface <./huggingface> | ||
Tensorflow <./tensorflow> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,7 @@ | |
name = "pylance" | ||
dependencies = ["pyarrow>=12", "numpy>=1.22"] | ||
description = "python wrapper for Lance columnar format" | ||
authors = [ | ||
{ name = "Lance Devs", email = "[email protected]" }, | ||
] | ||
authors = [{ name = "Lance Devs", email = "[email protected]" }] | ||
license = { file = "LICENSE" } | ||
repository = "https://github.com/eto-ai/lance" | ||
readme = "README.md" | ||
|
@@ -48,20 +46,18 @@ build-backend = "maturin" | |
|
||
[project.optional-dependencies] | ||
tests = [ | ||
"pandas", | ||
"pytest", | ||
"datasets", | ||
"duckdb", | ||
"ml_dtypes", | ||
"pillow", | ||
"pandas", | ||
"polars[pyarrow,pandas]", | ||
"pytest", | ||
"tensorflow", | ||
"tqdm", | ||
] | ||
benchmarks = [ | ||
"pytest-benchmark", | ||
] | ||
torch = [ | ||
"torch", | ||
] | ||
benchmarks = ["pytest-benchmark"] | ||
torch = ["torch"] | ||
|
||
[tool.ruff] | ||
select = ["F", "E", "W", "I", "G", "TCH", "PERF", "CPY001", "B019"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2023 Lance Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from pathlib import Path | ||
|
||
import lance | ||
import pytest | ||
|
||
datasets = pytest.importorskip("datasets") | ||
|
||
|
||
def test_write_hf_dataset(tmp_path: Path): | ||
hf_ds = datasets.load_dataset( | ||
"poloclub/diffusiondb", | ||
name="2m_first_1k", | ||
split="train[:50]", | ||
trust_remote_code=True, | ||
) | ||
|
||
ds = lance.write_dataset(hf_ds, tmp_path) | ||
assert ds.count_rows() == 50 | ||
|
||
assert ds.schema == hf_ds.features.arrow_schema |