Skip to content

Commit

Permalink
feat: Add basic support to bool features
Browse files Browse the repository at this point in the history
  • Loading branch information
frascuchon committed Oct 7, 2024
1 parent 485f3ff commit 1bd49e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions argilla/src/argilla/settings/_io/_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FeatureType(Enum):
LABEL = "label"
INT = "int"
FLOAT = "float"
BOOL = "bool"


class AttributeType(Enum):
Expand Down Expand Up @@ -117,6 +118,8 @@ def _map_feature_type(feature):
return FeatureType.INT
elif dtype in ["float32", "float64"]:
return FeatureType.FLOAT
elif dtype == "bool":
return FeatureType.BOOL
elif hf_type == "Image":
return FeatureType.IMAGE
elif hf_type == "ClassLabel":
Expand Down Expand Up @@ -260,6 +263,8 @@ def _define_settings_from_features(
metadata.append(IntegerMetadataProperty(name=name))
elif feature_type == FeatureType.FLOAT:
metadata.append(FloatMetadataProperty(name=name))
elif feature_type == FeatureType.BOOL:
metadata.append(TermsMetadataProperty(name=name))
else:
warnings.warn(f"Feature '{name}' has an unsupported type. Skipping. Feature type: {feature_type}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ def test_define_settings_from_features_with_non_curated_column_name(column: str,
assert settings.fields[0].name == name


def test_define_settings_from_bool_features():
features = {"text": {"_type": "Value", "dtype": "string"}, "bool_column": {"_type": "Value", "dtype": "bool"}}
settings = _define_settings_from_features(features, feature_mapping={})

assert len(settings.metadata) == 1
assert isinstance(settings.metadata[0], rg.TermsMetadataProperty)
assert settings.metadata[0].name == "bool_column"


@pytest.mark.parametrize("column", ["text<column", "text>column", "text|column", "text]column", "text/column"])
def test_define_settings_from_features_with_unsupported_column_name(column: str):
features = {column: {"_type": "Value", "dtype": "string"}}
Expand Down

0 comments on commit 1bd49e5

Please sign in to comment.