-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flag to allow or reject datasets containing unsafe types (i.e., P…
…ickle) (#519) * Add allow_unsafe_types. * is_mds_encodings_safe. * usefixtures. * Fix lint.
- Loading branch information
Showing
7 changed files
with
114 additions
and
7 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
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,53 @@ | ||
# Copyright 2023 MosaicML Streaming authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from typing import Tuple | ||
|
||
import pytest | ||
|
||
from streaming import MDSWriter, StreamingDataset | ||
|
||
|
||
@pytest.mark.usefixtures('local_remote_dir') | ||
def test_do_allow_unsafe_types_safe(local_remote_dir: Tuple[str, str]): | ||
local, _ = local_remote_dir | ||
columns = {'num': 'int'} | ||
with MDSWriter(out=local, columns=columns) as out: | ||
for num in range(100): | ||
sample = {'num': num} | ||
out.write(sample) | ||
StreamingDataset(local=local, allow_unsafe_types=True) | ||
|
||
|
||
@pytest.mark.usefixtures('local_remote_dir') | ||
def test_do_allow_unsafe_types_unsafe(local_remote_dir: Tuple[str, str]): | ||
local, _ = local_remote_dir | ||
columns = {'num': 'pkl'} | ||
with MDSWriter(out=local, columns=columns) as out: | ||
for num in range(100): | ||
sample = {'num': num} | ||
out.write(sample) | ||
StreamingDataset(local=local, allow_unsafe_types=True) | ||
|
||
|
||
@pytest.mark.usefixtures('local_remote_dir') | ||
def test_dont_allow_unsafe_types_safe(local_remote_dir: Tuple[str, str]): | ||
local, _ = local_remote_dir | ||
columns = {'num': 'int'} | ||
with MDSWriter(out=local, columns=columns) as out: | ||
for num in range(100): | ||
sample = {'num': num} | ||
out.write(sample) | ||
StreamingDataset(local=local) | ||
|
||
|
||
@pytest.mark.usefixtures('local_remote_dir') | ||
def test_dont_allow_unsafe_types_unsafe(local_remote_dir: Tuple[str, str]): | ||
local, _ = local_remote_dir | ||
columns = {'num': 'pkl'} | ||
with MDSWriter(out=local, columns=columns) as out: | ||
for num in range(100): | ||
sample = {'num': num} | ||
out.write(sample) | ||
with pytest.raises(ValueError, match='.*contains an unsafe type.*'): | ||
StreamingDataset(local=local) |