-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Thanks for your contribution! As part of our Community Growers initiative 🌱, we're donating Justdiggit bunds in your name to reforest sub-Saharan Africa. To claim your Community Growers certificate, please contact David Berenstein in our Slack community or fill in this form https://tally.so/r/n9XrxK once your PR has been merged. --> # Description Basic method to delete the records. Records are still ingested to be validated, but I don't think we need to allow data structures in this workflow. Closes #4930 **Type of change** (Please delete options that are not relevant. Remember to title the PR according to the type of change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Refactor (change restructuring the codebase without changing functionality) - [ ] Improvement (change adding some improvement to an existing functionality) **How Has This Been Tested** (Please describe the tests that you ran to verify your changes. And ideally, reference `tests`) - [ ] Test A - [ ] Test B **Checklist** - [ ] I added relevant documentation - [ ] I followed the style guidelines of this project - [ ] I did a self-review of my code - [ ] I made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK) (see text above) - [ ] I have added relevant notes to the `CHANGELOG.md` file (See https://keepachangelog.com/) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: David Berenstein <[email protected]>
- Loading branch information
1 parent
083932e
commit e7efb09
Showing
4 changed files
with
164 additions
and
5 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
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,102 @@ | ||
# Copyright 2024-present, Argilla, Inc. | ||
# | ||
# 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. | ||
|
||
import uuid | ||
import pytest | ||
|
||
import argilla_sdk as rg | ||
|
||
|
||
@pytest.fixture | ||
def dataset(client: rg.Argilla) -> rg.Dataset: | ||
workspace = client.workspaces[0] | ||
mock_dataset_name = f"test_delete_records_{uuid.uuid1()}" | ||
settings = rg.Settings( | ||
allow_extra_metadata=True, | ||
fields=[ | ||
rg.TextField(name="text"), | ||
], | ||
questions=[ | ||
rg.TextQuestion(name="label", use_markdown=False), | ||
], | ||
) | ||
dataset = rg.Dataset( | ||
name=mock_dataset_name, | ||
workspace=workspace.name, | ||
settings=settings, | ||
client=client, | ||
) | ||
dataset.create() | ||
return dataset | ||
|
||
|
||
def test_delete_records(client: rg.Argilla, dataset: rg.Dataset): | ||
mock_data = [ | ||
{ | ||
"text": "Hello World, how are you?", | ||
"label": "negative", | ||
"id": uuid.uuid4(), | ||
}, | ||
{ | ||
"text": "Hello World, how are you?", | ||
"label": "negative", | ||
"id": uuid.uuid4(), | ||
}, | ||
{ | ||
"text": "Hello World, how are you?", | ||
"label": "negative", | ||
"id": uuid.uuid4(), | ||
}, | ||
] | ||
|
||
dataset.records.log(records=mock_data) | ||
records_to_delete = list(dataset.records)[:2] | ||
dataset.records.delete(records_to_delete) | ||
dataset_records = list(dataset.records) | ||
|
||
assert len(dataset_records) == 1 | ||
assert dataset_records[0].id == str(mock_data[2]["id"]) | ||
|
||
for record in dataset_records: | ||
assert record.id not in [record.id for record in records_to_delete] | ||
|
||
|
||
def test_delete_single_record(client: rg.Argilla, dataset: rg.Dataset): | ||
mock_data = [ | ||
{ | ||
"text": "Hello World, how are you?", | ||
"label": "negative", | ||
"id": uuid.uuid4(), | ||
}, | ||
{ | ||
"text": "Hello World, how are you?", | ||
"label": "negative", | ||
"id": uuid.uuid4(), | ||
}, | ||
{ | ||
"text": "Hello World, how are you?", | ||
"label": "negative", | ||
"id": uuid.uuid4(), | ||
}, | ||
] | ||
|
||
dataset.records.log(records=mock_data) | ||
records_to_delete = [list(dataset.records)[1]] | ||
dataset.records.delete(records_to_delete) | ||
dataset_records = list(dataset.records) | ||
|
||
assert len(dataset_records) == 2 | ||
assert dataset_records[0].id == str(mock_data[0]["id"]) | ||
assert dataset_records[1].id == str(mock_data[2]["id"]) | ||
assert mock_data[1]["id"] not in [record.id for record in dataset_records] |