You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@hamilton.apache.org by "jernejfrank (via GitHub)" <gi...@apache.org> on 2026/08/17 08:48:46 UTC

Re: [PR] docs(data-quality): add check_output_custom section (#212) [hamilton]

jernejfrank commented on code in PR #1658:
URL: https://github.com/apache/hamilton/pull/1658#discussion_r3794943273


##########
docs/how-tos/run-data-quality-checks.rst:
##########
@@ -11,6 +11,102 @@ The goal of this is to show how to use runtime data quality checks in a larger,
 1. `Data quality with hamilton <https://github.com/apache/hamilton/tree/main/examples/data_quality/simple>`_
 2. `Data quality with pandera <https://github.com/apache/hamilton/tree/main/examples/data_quality/pandera>`_
 
+Custom validators
+~~~~~~~~~~~~~~~~~
+
+The ``@check_output`` decorator ships with default validators that cover common checks (data type, range, allowed values, etc. -- see the :doc:`check_output reference <../reference/decorators/check_output>`). When you need a check they don't cover -- say, a business rule specific to your data -- you can write your own validator class and apply it with ``@check_output_custom``.
+
+A validator subclasses ``hamilton.data_quality.base.DataValidator`` and implements four methods, plus a constructor that forwards ``importance`` to the base class:
+
+.. code-block:: python
+
+    # my_module.py
+    import pandas as pd
+
+    from hamilton.data_quality import base
+
+
+    class AllPositiveValidator(base.DataValidator):
+        """Validates that a pandas series contains no negative values."""
+
+        def __init__(self, importance: str):
+            super().__init__(importance=importance)
+
+        @classmethod
+        def applies_to(cls, datatype: type) -> bool:
+            return issubclass(datatype, pd.Series)
+
+        def description(self) -> str:
+            return "Validates that the series contains no negative values."
+
+        @classmethod
+        def name(cls) -> str:
+            return "all_positive_validator"
+
+        def validate(self, dataset: pd.Series) -> base.ValidationResult:
+            negative_count = int((dataset < 0).sum())
+            passes = negative_count == 0
+            if passes:
+                message = "All values are non-negative."
+            else:
+                message = f"Found {negative_count} negative value(s)."
+            return base.ValidationResult(
+                passes=passes,
+                message=message,
+                diagnostics={"negative_count": negative_count, "series_length": len(dataset)},
+            )
+
+The pieces are:
+
+* ``applies_to`` -- whether this validator can run on the output type of the decorated function.

Review Comment:
   So turns out this actually does not fire on the custom validator route. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@hamilton.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org