Skip to content

Commit

Permalink
[BUGFIX] argilla: Add support for visible_for_annotators on `__in…
Browse files Browse the repository at this point in the history
…it__` attribute to integer and float metadata (#5364)

# Description
<!-- 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 #5360 

**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)

**How Has This Been Tested**
<!-- Please add some reference about how your feature has been tested.
-->

**Checklist**
<!-- Please go over the list and make sure you've taken everything into
account -->

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)
  • Loading branch information
frascuchon authored Aug 1, 2024
1 parent f4e7177 commit ae28672
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions argilla/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ These are the section headers that we use:

## [Unreleased]()

### Fixed

- Fixed error creating integer and float metadata with `visible_for_annotators`. ([#5364](https://github.com/argilla-io/argilla/pull/5364))

## [2.0.0](https://github.com/argilla-io/argilla/compare/v2.0.0rc1...v2.0.0)

### Added
Expand Down
10 changes: 7 additions & 3 deletions argilla/src/argilla/settings/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def dataset(self, value: "Dataset") -> None:
self._with_client(self._dataset._client)

def __repr__(self) -> str:
return (
f"{self.__class__.__name__}(name={self.name}, title={self.title}, dimensions={self.visible_for_annotators})"
)
return f"{self.__class__.__name__}(name={self.name}, title={self.title}, visible_for_annotators={self.visible_for_annotators})"

def _with_client(self, client: "Argilla") -> "Self":
# TODO: Review and simplify. Maybe only one of them is required
Expand Down Expand Up @@ -158,6 +156,7 @@ def __init__(
min: Optional[float] = None,
max: Optional[float] = None,
title: Optional[str] = None,
visible_for_annotators: Optional[bool] = True,
client: Optional[Argilla] = None,
) -> None:
"""Create a metadata field with float settings.
Expand All @@ -167,6 +166,7 @@ def __init__(
min (Optional[float]): The minimum value
max (Optional[float]): The maximum value
title (Optional[str]): The title of the metadata field
visible_for_annotators (Optional[bool]): Whether the metadata field is visible for annotators
client (Optional[Argilla]): The client to use for API requests
Raises:
MetadataError: If an error occurs while defining metadata settings
Expand All @@ -185,6 +185,7 @@ def __init__(
type=MetadataPropertyType.float,
title=title,
settings=settings,
visible_for_annotators=visible_for_annotators,
)

@property
Expand Down Expand Up @@ -218,6 +219,7 @@ def __init__(
min: Optional[int] = None,
max: Optional[int] = None,
title: Optional[str] = None,
visible_for_annotators: Optional[bool] = True,
client: Optional[Argilla] = None,
) -> None:
"""Create a metadata field with integer settings.
Expand All @@ -227,6 +229,7 @@ def __init__(
min (Optional[int]): The minimum value
max (Optional[int]): The maximum value
title (Optional[str]): The title of the metadata field
visible_for_annotators (Optional[bool]): Whether the metadata field is visible for annotators
Raises:
MetadataError: If an error occurs while defining metadata settings
"""
Expand All @@ -242,6 +245,7 @@ def __init__(
type=MetadataPropertyType.integer,
title=title,
settings=settings,
visible_for_annotators=visible_for_annotators,
)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from argilla._models import MetadataFieldModel, TermsMetadataPropertySettings


class TestTermsMetadata:
class TestMetadata:
def test_create_metadata_terms(self):
property = rg.TermsMetadataProperty(
title="A metadata property", name="metadata", options=["option1", "option2"]
Expand Down Expand Up @@ -81,3 +81,11 @@ def test_create_from_model(self):
assert property.name == "metadata"
assert property.visible_for_annotators is True
assert property.options == ["option1", "option2"]

def test_create_integer_metadata_with_visible_for_annotators(self):
metadata = rg.IntegerMetadataProperty(name="integer", min=10, visible_for_annotators=False)
assert metadata.visible_for_annotators is False

def test_create_float_metadata_with_visible_for_annotators(self):
metadata = rg.FloatMetadataProperty(name="integer", min=3.5, max=10.5, visible_for_annotators=False)
assert metadata.visible_for_annotators is False

0 comments on commit ae28672

Please sign in to comment.