From a3f27c6bcc9e6bd2ed3983cf95b834f09c78d854 Mon Sep 17 00:00:00 2001 From: Ankush-Chander Date: Sat, 7 Jan 2023 21:51:49 +0530 Subject: [PATCH 1/4] add repr method for Rule, Dataset. --- src/argilla/client/datasets.py | 9 +++++++++ src/argilla/labeling/text_classification/rule.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/argilla/client/datasets.py b/src/argilla/client/datasets.py index 8f773e8344..b94780db10 100644 --- a/src/argilla/client/datasets.py +++ b/src/argilla/client/datasets.py @@ -656,6 +656,15 @@ def prepare_for_training(self) -> "datasets.Dataset": ds_dict, features=datasets.Features(feature_dict) ) + def __repr__(self): + header_string = f"{''.ljust(4)}\t{'text'.ljust(30)}\t{'annotation'}\t{'prediction'}" + repr_list = [f"{str(i).ljust(4)}\t{rec.text[:30].ljust(30)}\t{str(rec.annotation).ljust(10)}\t{str(rec.prediction).ljust(10)}" for i, rec in enumerate(self._records[:5])] + record_string = "\n".join(repr_list) + count_string = f"{len(self._records)} TextClassificationRecord records" + return "\n".join([header_string, record_string,"...", count_string]) + + def __str__(self): + return repr(self) class Framework(Enum): TRANSFORMERS = "transformers" diff --git a/src/argilla/labeling/text_classification/rule.py b/src/argilla/labeling/text_classification/rule.py index b9d6160313..5304fb3296 100644 --- a/src/argilla/labeling/text_classification/rule.py +++ b/src/argilla/labeling/text_classification/rule.py @@ -172,6 +172,13 @@ def __call__( else: return self._label + def __repr__(self): + """The rule representation.""" + return f"Rule(query='{self.query}', label='{self.label}', name='{self.name}')" + + def __str__(self): + """The rule string representation.""" + return repr(self) def add_rules(dataset: str, rules: List[Rule]): """Adds the rules to a given dataset From 2b6526ce0a8b5d03676330374be8ab4d0c720466 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Jan 2023 16:31:00 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/argilla/client/datasets.py | 12 +++++++++--- src/argilla/labeling/text_classification/rule.py | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/argilla/client/datasets.py b/src/argilla/client/datasets.py index b94780db10..11255fdb78 100644 --- a/src/argilla/client/datasets.py +++ b/src/argilla/client/datasets.py @@ -657,15 +657,21 @@ def prepare_for_training(self) -> "datasets.Dataset": ) def __repr__(self): - header_string = f"{''.ljust(4)}\t{'text'.ljust(30)}\t{'annotation'}\t{'prediction'}" - repr_list = [f"{str(i).ljust(4)}\t{rec.text[:30].ljust(30)}\t{str(rec.annotation).ljust(10)}\t{str(rec.prediction).ljust(10)}" for i, rec in enumerate(self._records[:5])] + header_string = ( + f"{''.ljust(4)}\t{'text'.ljust(30)}\t{'annotation'}\t{'prediction'}" + ) + repr_list = [ + f"{str(i).ljust(4)}\t{rec.text[:30].ljust(30)}\t{str(rec.annotation).ljust(10)}\t{str(rec.prediction).ljust(10)}" + for i, rec in enumerate(self._records[:5]) + ] record_string = "\n".join(repr_list) count_string = f"{len(self._records)} TextClassificationRecord records" - return "\n".join([header_string, record_string,"...", count_string]) + return "\n".join([header_string, record_string, "...", count_string]) def __str__(self): return repr(self) + class Framework(Enum): TRANSFORMERS = "transformers" SPACY = "spacy" diff --git a/src/argilla/labeling/text_classification/rule.py b/src/argilla/labeling/text_classification/rule.py index 5304fb3296..658e63f7fc 100644 --- a/src/argilla/labeling/text_classification/rule.py +++ b/src/argilla/labeling/text_classification/rule.py @@ -180,6 +180,7 @@ def __str__(self): """The rule string representation.""" return repr(self) + def add_rules(dataset: str, rules: List[Rule]): """Adds the rules to a given dataset From fa1f74295dd2daa4d5148ee5e64d0a7604515d06 Mon Sep 17 00:00:00 2001 From: Ankush-Chander Date: Sat, 28 Jan 2023 13:02:44 +0530 Subject: [PATCH 3/4] reuse for repr --- src/argilla/client/datasets.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/argilla/client/datasets.py b/src/argilla/client/datasets.py index 11255fdb78..225d0a1491 100644 --- a/src/argilla/client/datasets.py +++ b/src/argilla/client/datasets.py @@ -657,16 +657,7 @@ def prepare_for_training(self) -> "datasets.Dataset": ) def __repr__(self): - header_string = ( - f"{''.ljust(4)}\t{'text'.ljust(30)}\t{'annotation'}\t{'prediction'}" - ) - repr_list = [ - f"{str(i).ljust(4)}\t{rec.text[:30].ljust(30)}\t{str(rec.annotation).ljust(10)}\t{str(rec.prediction).ljust(10)}" - for i, rec in enumerate(self._records[:5]) - ] - record_string = "\n".join(repr_list) - count_string = f"{len(self._records)} TextClassificationRecord records" - return "\n".join([header_string, record_string, "...", count_string]) + return repr(self.to_pandas()) def __str__(self): return repr(self) From 2234032c9defaaaefda357e9e676cb33dd8baf9c Mon Sep 17 00:00:00 2001 From: Ankush-Chander Date: Mon, 30 Jan 2023 21:48:46 +0530 Subject: [PATCH 4/4] move repr/str methods to base class. --- src/argilla/client/datasets.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/argilla/client/datasets.py b/src/argilla/client/datasets.py index 225d0a1491..6ca0741988 100644 --- a/src/argilla/client/datasets.py +++ b/src/argilla/client/datasets.py @@ -141,6 +141,12 @@ def __delitem__(self, key): def __len__(self) -> int: return len(self._records) + def __repr__(self): + return repr(self.to_pandas()) + + def __str__(self): + return repr(self) + @_requires_datasets def to_datasets(self) -> "datasets.Dataset": """Exports your records to a `datasets.Dataset`. @@ -656,12 +662,6 @@ def prepare_for_training(self) -> "datasets.Dataset": ds_dict, features=datasets.Features(feature_dict) ) - def __repr__(self): - return repr(self.to_pandas()) - - def __str__(self): - return repr(self) - class Framework(Enum): TRANSFORMERS = "transformers"