-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Update format, fingerprint and indices after add_item #2254
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a877fff
update format, fingerprint and indices after add_item
lhoestq 3bd47e5
minor
lhoestq cffbd63
rename to item_indices_table
lhoestq f834767
test dataset._indices
lhoestq d93bc76
Merge branch 'master' into add_item2
lhoestq 88676c9
fix class_encode_column issue
lhoestq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
update format, fingerprint and indices after add_item
- Loading branch information
commit a877fffd9f1e90cea45dac788a3649312fab64af
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1948,6 +1948,10 @@ def test_concatenate_datasets_duplicate_columns(dataset): | |
assert "duplicated" in str(excinfo.value) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"transform", | ||
[None, ("shuffle", (42,), {}), ("with_format", ("pandas",), {}), ("class_encode_column", ("col_2",), {})], | ||
) | ||
@pytest.mark.parametrize("in_memory", [False, True]) | ||
@pytest.mark.parametrize( | ||
"item", | ||
|
@@ -1958,22 +1962,28 @@ def test_concatenate_datasets_duplicate_columns(dataset): | |
{"col_1": 4.0, "col_2": 4.0, "col_3": 4.0}, | ||
], | ||
) | ||
def test_dataset_add_item(item, in_memory, dataset_dict, arrow_path): | ||
dataset = ( | ||
def test_dataset_add_item(item, in_memory, dataset_dict, arrow_path, transform): | ||
dataset_to_test = ( | ||
Dataset(InMemoryTable.from_pydict(dataset_dict)) | ||
if in_memory | ||
else Dataset(MemoryMappedTable.from_file(arrow_path)) | ||
) | ||
dataset = dataset.add_item(item) | ||
if transform is not None: | ||
transform_name, args, kwargs = transform | ||
dataset_to_test: Dataset = getattr(dataset_to_test, transform_name)(*args, **kwargs) | ||
dataset = dataset_to_test.add_item(item) | ||
assert dataset.data.shape == (5, 3) | ||
expected_features = {"col_1": "string", "col_2": "int64", "col_3": "float64"} | ||
expected_features = dataset_to_test.features | ||
assert dataset.data.column_names == list(expected_features.keys()) | ||
for feature, expected_dtype in expected_features.items(): | ||
assert dataset.features[feature].dtype == expected_dtype | ||
assert len(dataset.data.blocks) == 1 if in_memory else 2 # multiple InMemoryTables are consolidated as one | ||
dataset = dataset.add_item(item) | ||
assert dataset.data.shape == (6, 3) | ||
assert dataset.features[feature] == expected_dtype | ||
assert len(dataset.data.blocks) == 1 if in_memory else 2 # multiple InMemoryTables are consolidated as one | ||
assert dataset.format["type"] == dataset_to_test.format["type"] | ||
assert dataset._fingerprint != dataset_to_test._fingerprint | ||
dataset.reset_format() | ||
dataset_to_test.reset_format() | ||
assert dataset[:-1] == dataset_to_test[:] | ||
assert {k: int(v) for k, v in dataset[-1].items()} == {k: int(v) for k, v in item.items()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to introduce an explicit test for the _indices? For example, this test passes even if I wrongly set in new_indices_array = pa.array([9], type=pa.uint64()) |
||
|
||
|
||
@pytest.mark.parametrize("keep_in_memory", [False, True]) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe calling it
item_indices_table
to be consistent withitem_table
above.