-
Notifications
You must be signed in to change notification settings - Fork 153
feat(datasets): accept pep version spec in read_dataset #1178
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b69f9f
feat(datasets): accept pep version spec in read_dataset
shcheklein 22ac7eb
add func tests for version specs
shcheklein 5636df8
simplify tests
shcheklein 30e3eff
simplify tests
shcheklein 3187ae4
refactor to properly handle remote datasets
shcheklein 6dc360a
fix tests
shcheklein 0fc72e7
add proper exception to get remote dataset
shcheklein 7eb29e2
fix tests
shcheklein 7455288
add tests for remote dataset read
shcheklein 105a2e4
improve docs for update flag
shcheklein 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
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,9 +7,6 @@ | |
| ProjectNotFoundError, | ||
| ) | ||
| from datachain.lib.dataset_info import DatasetInfo | ||
| from datachain.lib.file import ( | ||
| File, | ||
| ) | ||
| from datachain.lib.projects import get as get_project | ||
| from datachain.lib.settings import Settings | ||
| from datachain.lib.signal_schema import SignalSchema | ||
|
|
@@ -34,7 +31,6 @@ def read_dataset( | |
| version: Optional[Union[str, int]] = None, | ||
| session: Optional[Session] = None, | ||
| settings: Optional[dict] = None, | ||
| fallback_to_studio: bool = True, | ||
| delta: Optional[bool] = False, | ||
| delta_on: Optional[Union[str, Sequence[str]]] = ( | ||
| "file.path", | ||
|
|
@@ -44,6 +40,7 @@ def read_dataset( | |
| delta_result_on: Optional[Union[str, Sequence[str]]] = None, | ||
| delta_compare: Optional[Union[str, Sequence[str]]] = None, | ||
| delta_retry: Optional[Union[bool, str]] = None, | ||
| update: bool = False, | ||
| ) -> "DataChain": | ||
| """Get data from a saved Dataset. It returns the chain itself. | ||
| If dataset or version is not found locally, it will try to pull it from Studio. | ||
|
|
@@ -55,11 +52,12 @@ def read_dataset( | |
| set; otherwise, default values will be applied. | ||
| namespace : optional name of namespace in which dataset to read is created | ||
| project : optional name of project in which dataset to read is created | ||
| version : dataset version | ||
| version : dataset version. Supports: | ||
| - Exact version strings: "1.2.3" | ||
| - Legacy integer versions: 1, 2, 3 (finds latest major version) | ||
| - Version specifiers (PEP 440): ">=1.0.0,<2.0.0", "~=1.4.2", "==1.2.*", etc. | ||
| session : Session to use for the chain. | ||
| settings : Settings to use for the chain. | ||
| fallback_to_studio : Try to pull dataset from Studio if not found locally. | ||
| Default is True. | ||
| delta: If True, only process new or changed files instead of reprocessing | ||
| everything. This saves time by skipping files that were already processed in | ||
| previous versions. The optimization is working when a new version of the | ||
|
|
@@ -79,6 +77,8 @@ def read_dataset( | |
| (error mode) | ||
| - True: Reprocess records missing from the result dataset (missing mode) | ||
| - None: No retry processing (default) | ||
| update: If True, it checks updates for the updates of the dataset on the Studio | ||
|
shcheklein marked this conversation as resolved.
Outdated
|
||
| side. | ||
|
|
||
| Example: | ||
| ```py | ||
|
|
@@ -92,11 +92,17 @@ def read_dataset( | |
| ``` | ||
|
|
||
| ```py | ||
| chain = dc.read_dataset("my_cats", fallback_to_studio=False) | ||
| chain = dc.read_dataset("my_cats", version="1.0.0") | ||
|
Contributor
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. why don't we make this a part of dataset name? like So, we can give up a whole parameter from almost every API call 🙂 |
||
| ``` | ||
|
|
||
| ```py | ||
| chain = dc.read_dataset("my_cats", version="1.0.0") | ||
| # Using version specifiers (PEP 440) | ||
| chain = dc.read_dataset("my_cats", version=">=1.0.0,<2.0.0") | ||
| ``` | ||
|
|
||
| ```py | ||
| # Legacy integer version support (finds latest in major version) | ||
| chain = dc.read_dataset("my_cats", version=1) # Latest 1.x.x version | ||
| ``` | ||
|
|
||
| ```py | ||
|
|
@@ -113,14 +119,15 @@ def read_dataset( | |
| version="1.0.0", | ||
| session=session, | ||
| settings=settings, | ||
| fallback_to_studio=True, | ||
|
shcheklein marked this conversation as resolved.
|
||
| ) | ||
| ``` | ||
| """ | ||
| from datachain.telemetry import telemetry | ||
|
|
||
| from .datachain import DataChain | ||
|
|
||
| telemetry.send_event_once("class", "datachain_init", name=name, version=version) | ||
|
|
||
| session = Session.get(session) | ||
| catalog = session.catalog | ||
|
|
||
|
|
@@ -131,31 +138,37 @@ def read_dataset( | |
| ) | ||
|
|
||
| if version is not None: | ||
| dataset = session.catalog.get_dataset_with_remote_fallback( | ||
| name, namespace_name, project_name, update=update | ||
| ) | ||
|
|
||
| # Convert legacy integer versions to version specifiers | ||
| # For backward compatibility we still allow users to put version as integer | ||
| # in which case we convert it to a version specifier that finds the latest | ||
| # version where major part is equal to that input version. | ||
| # For example if user sets version=2, we convert it to ">=2.0.0,<3.0.0" | ||
| # which will find something like 2.4.3 (assuming 2.4.3 is the biggest among | ||
| # all 2.* dataset versions) | ||
| if isinstance(version, int): | ||
| version_spec = f">={version}.0.0,<{version + 1}.0.0" | ||
| else: | ||
| version_spec = str(version) | ||
|
|
||
| from packaging.specifiers import InvalidSpecifier, SpecifierSet | ||
|
shcheklein marked this conversation as resolved.
|
||
|
|
||
| try: | ||
| # for backward compatibility we still allow users to put version as integer | ||
| # in which case we are trying to find latest version where major part is | ||
| # equal to that input version. For example if user sets version=2, we could | ||
| # continue with something like 2.4.3 (assuming 2.4.3 is the biggest among | ||
| # all 2.* dataset versions). If dataset doesn't have any versions where | ||
| # major part is equal to that input, exception is thrown. | ||
| major = int(version) | ||
| try: | ||
| ds_project = get_project(project_name, namespace_name, session=session) | ||
| except ProjectNotFoundError: | ||
| raise DatasetNotFoundError( | ||
| f"Dataset {name} not found in namespace {namespace_name} and", | ||
| f" project {project_name}", | ||
| ) from None | ||
|
|
||
| dataset = session.catalog.get_dataset(name, ds_project) | ||
| latest_major = dataset.latest_major_version(major) | ||
| if not latest_major: | ||
| # Try to parse as version specifier | ||
| SpecifierSet(version_spec) | ||
| # If it's a valid specifier set, find the latest compatible version | ||
| latest_compatible = dataset.latest_compatible_version(version_spec) | ||
| if not latest_compatible: | ||
| raise DatasetVersionNotFoundError( | ||
| f"Dataset {name} does not have version {version}" | ||
| f"No dataset {name} version matching specifier {version_spec}" | ||
| ) | ||
| version = latest_major | ||
| except ValueError: | ||
| # version is in new semver string format, continuing as normal | ||
| version = latest_compatible | ||
| except InvalidSpecifier: | ||
| # If not a valid specifier, treat as exact version string | ||
| # This handles cases like "1.2.3" which are exact versions, not specifiers | ||
| pass | ||
|
|
||
| if settings: | ||
|
|
@@ -169,11 +182,8 @@ def read_dataset( | |
| namespace_name=namespace_name, | ||
| version=version, # type: ignore[arg-type] | ||
| session=session, | ||
| indexing_column_types=File._datachain_column_types, | ||
| fallback_to_studio=fallback_to_studio, | ||
| ) | ||
|
|
||
| telemetry.send_event_once("class", "datachain_init", name=name, version=version) | ||
| signals_schema = SignalSchema({"sys": Sys}) | ||
| if query.feature_schema: | ||
| signals_schema |= SignalSchema.deserialize(query.feature_schema) | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.