Skip to content

Commit 03fe070

Browse files
sajmarulhoestq
andauthored
Fix 7846: add_column and add_item erroneously(?) require new_fingerprint parameter (#7884)
* fix 7846 * Update tests/test_arrow_dataset.py * make style * Update arrow_dataset.py * make style --------- Co-authored-by: Quentin Lhoest <[email protected]>
1 parent 004a5bf commit 03fe070

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/datasets/arrow_dataset.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6076,7 +6076,11 @@ def get_deletions_and_dataset_card() -> tuple[str, list[CommitOperationDelete],
60766076
@transmit_format
60776077
@fingerprint_transform(inplace=False)
60786078
def add_column(
6079-
self, name: str, column: Union[list, np.ndarray], new_fingerprint: str, feature: Optional[FeatureType] = None
6079+
self,
6080+
name: str,
6081+
column: Union[list, np.ndarray],
6082+
new_fingerprint: Optional[str] = None,
6083+
feature: Optional[FeatureType] = None,
60806084
):
60816085
"""Add column to Dataset.
60826086
@@ -6333,7 +6337,7 @@ def add_elasticsearch_index(
63336337

63346338
@transmit_format
63356339
@fingerprint_transform(inplace=False)
6336-
def add_item(self, item: dict, new_fingerprint: str):
6340+
def add_item(self, item: dict, new_fingerprint: Optional[str] = None):
63376341
"""Add item to Dataset.
63386342
63396343
<Added version="1.7"/>

tests/test_arrow_dataset.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4783,3 +4783,13 @@ def test_from_polars_save_to_disk_and_load_from_disk_round_trip_with_large_list(
47834783
def test_polars_round_trip():
47844784
ds = Dataset.from_dict({"x": [[1, 2], [3, 4, 5]], "y": ["a", "b"]})
47854785
assert isinstance(Dataset.from_polars(ds.to_polars()), Dataset)
4786+
4787+
4788+
def test_add_column():
4789+
from datasets import Dataset
4790+
4791+
ds = Dataset.from_dict({"a": [1, 2]})
4792+
ds = ds.add_column("b", [3, 4])
4793+
assert "b" in ds.features
4794+
assert ds[0] == {"a": 1, "b": 3}
4795+
assert ds[1] == {"a": 2, "b": 4}

0 commit comments

Comments
 (0)