Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/galileo/__future__/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,33 @@ def get(cls, *, id: str | None = None, name: str | None = None) -> Dataset | Non
"""
Get an existing dataset by ID or name.

.. note::
Lookup behavior differs depending on which parameter is used:

- **By ID**: the API performs a direct lookup. If no dataset with that ID exists,
a ``NotFoundError`` is raised.
- **By name**: the API performs a filtered list query. If no dataset with that name
exists, ``None`` is returned (no exception is raised).

Args:
id (Optional[str]): The dataset ID.
name (Optional[str]): The dataset name.

Returns
-------
Optional[Dataset]: The dataset if found, None otherwise.
Optional[Dataset]: The dataset if found, or ``None`` if looked up by name and no match exists.

Raises
------
NotFoundError: If looked up by ID and no dataset with that ID exists.
ValueError: If neither or both id and name are provided.

Examples
--------
# Get by name
# Get by name — returns None if not found
dataset = Dataset.get(name="geography-questions")

# Get by ID
# Get by ID — raises NotFoundError if not found
dataset = Dataset.get(id="dataset-123")
"""
datasets_service = Datasets()
Expand Down
32 changes: 24 additions & 8 deletions src/galileo/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ def get(

Optionally validates that the dataset is used in a specific project.

.. note::
Lookup behavior differs depending on which parameter is used:

- **By ID**: the API performs a direct lookup. If no dataset with that ID exists,
a ``NotFoundError`` is raised.
- **By name**: the API performs a filtered list query. If no dataset with that name
exists, ``None`` is returned (no exception is raised).

Parameters
----------
id : str
Expand All @@ -300,17 +308,17 @@ def get(

Returns
-------
Dataset
The dataset.
Optional[Dataset]
The dataset if found, or ``None`` if looked up by name and no match exists.

Raises
------
NotFoundError
If looked up by ID and no dataset with that ID exists.
ValueError
If neither or both `id` and `name` are provided, if both project_id and project_name
are provided, or if the specified project does not exist, or if the dataset is not
used in the specified project.
errors.UnexpectedStatus
If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException
If the request takes longer than Client.timeout.

Expand Down Expand Up @@ -666,6 +674,14 @@ def get_dataset(

Optionally validates that the dataset is used in a specific project.

.. note::
Lookup behavior differs depending on which parameter is used:

- **By ID**: the API performs a direct lookup. If no dataset with that ID exists,
a ``NotFoundError`` is raised.
- **By name**: the API performs a filtered list query. If no dataset with that name
exists, ``None`` is returned (no exception is raised).

Parameters
----------
id : str
Expand All @@ -679,17 +695,17 @@ def get_dataset(

Returns
-------
Dataset
The dataset.
Optional[Dataset]
The dataset if found, or ``None`` if looked up by name and no match exists.

Raises
------
NotFoundError
If looked up by ID and no dataset with that ID exists.
ValueError
If neither or both `id` and `name` are provided, if both project_id and project_name
are provided, or if the specified project does not exist, or if the dataset is not
used in the specified project.
errors.UnexpectedStatus
If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException
If the request takes longer than Client.timeout.

Expand Down
Loading