Skip to content

Commit

Permalink
[ENHANCEMENT] stop warning on existing datasets (#4987)
Browse files Browse the repository at this point in the history
This PR supprses warning for existing datasets which means that warnings
are hidden when gettings datasets from the server here: #4928

# Argilla Community Growers

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.

# Pull Request Templates

Please go the the `Preview` tab and select the appropriate sub-template:

* [🐞-bug](?expand=1&template=bug.md)
* [📚-documentation](?expand=1&template=docs.md)
* [🆕-features](?expand=1&template=features.md)

# Generic Pull Request Template

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context. List any dependencies that
are required for this change.

Closes #<issue_number>

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**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
- [ ] follows 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>
  • Loading branch information
burtenshaw and pre-commit-ci[bot] authored Jun 12, 2024
1 parent a667a90 commit 083932e
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions argilla-sdk/src/argilla_sdk/datasets/_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ def __init__(
self._log_message(f"Settings dataset name to unique UUID: {name}")

self.workspace_id = (
_model.workspace_id
if _model and _model.workspace_id
else self.__workspace_id_from_name(workspace=workspace)
_model.workspace_id if _model and _model.workspace_id else self._workspace_id_from_name(workspace=workspace)
)
self._model = _model or DatasetModel(
name=name,
workspace_id=UUIDUtilities.convert_optional_uuid(uuid=self.workspace_id),
)
self._settings = self.__configure_settings_for_dataset(settings=settings)
self._settings = settings or Settings(_dataset=self)
self._settings.dataset = self
self.__records = DatasetRecords(client=self._client, dataset=self)

#####################
Expand All @@ -102,13 +101,14 @@ def records(self) -> "DatasetRecords":

@property
def settings(self) -> Settings:
if self.__is_published() and self._settings.is_outdated:
if self._is_published() and self._settings.is_outdated:
self._settings.get()
return self._settings

@settings.setter
def settings(self, value: Settings) -> None:
self._settings = self.__configure_settings_for_dataset(settings=value)
value.dataset = self
self._settings = value

@property
def fields(self) -> list:
Expand Down Expand Up @@ -161,7 +161,7 @@ def create(self) -> "Dataset":
return self._publish()
except Exception as e:
self._log_message(message=f"Error creating dataset: {e}", level="error")
self.__rollback_dataset_creation()
self._rollback_dataset_creation()
raise SettingsError from e

def update(self) -> "Dataset":
Expand All @@ -187,22 +187,7 @@ def _publish(self) -> "Dataset":

return self.get() # type: ignore

def __configure_settings_for_dataset(
self,
settings: Optional[Settings] = None,
) -> Settings:
if settings is None:
settings = Settings(_dataset=self)
warnings.warn(
message="Settings not provided. Using empty settings for the dataset. \
Define the settings before creating the dataset.",
stacklevel=2,
)
else:
settings.dataset = self
return settings

def __workspace_id_from_name(self, workspace: Optional[Union["Workspace", str]]) -> UUID:
def _workspace_id_from_name(self, workspace: Optional[Union["Workspace", str]]) -> UUID:
if workspace is None:
available_workspaces = self._client.workspaces
ws = available_workspaces[0] # type: ignore
Expand All @@ -221,9 +206,9 @@ def __workspace_id_from_name(self, workspace: Optional[Union["Workspace", str]])
ws = workspace
return ws.id

def __rollback_dataset_creation(self):
if self.exists() and not self.__is_published():
def _rollback_dataset_creation(self):
if self.exists() and not self._is_published():
self.delete()

def __is_published(self) -> bool:
def _is_published(self) -> bool:
return self.exists() and self._model.status == "ready"

0 comments on commit 083932e

Please sign in to comment.