This is an automated email from the ASF dual-hosted git repository.

vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new e494b868cf7 Add docstrings for missing methods for hf provider. 
(#77536)
e494b868cf7 is described below

commit e494b868cf7aca91720031a973c7080b1cf2f661
Author: Parag Ekbote <[email protected]>
AuthorDate: Tue Nov 24 19:50:18 2026 +0530

    Add docstrings for missing methods for hf provider. (#77536)
---
 .../src/airflow/providers/huggingface/assets/huggingface.py  |  1 +
 .../src/airflow/providers/huggingface/hooks/huggingface.py   |  7 +++++++
 .../src/airflow/providers/huggingface/operators/datasets.py  | 12 ++++++++++++
 3 files changed, 20 insertions(+)

diff --git 
a/providers/huggingface/src/airflow/providers/huggingface/assets/huggingface.py 
b/providers/huggingface/src/airflow/providers/huggingface/assets/huggingface.py
index e4cd49ad3dc..6894051e7bb 100644
--- 
a/providers/huggingface/src/airflow/providers/huggingface/assets/huggingface.py
+++ 
b/providers/huggingface/src/airflow/providers/huggingface/assets/huggingface.py
@@ -33,6 +33,7 @@ def sanitize_uri(uri: SplitResult) -> SplitResult:
 
 
 def _sanitize_uri_string(uri: str) -> str:
+    """Return a string URI with the canonical form applied when needed."""
     parsed = urlsplit(uri)
     normalized = sanitize_uri(parsed)
     return uri if normalized == parsed else urlunsplit(normalized)
diff --git 
a/providers/huggingface/src/airflow/providers/huggingface/hooks/huggingface.py 
b/providers/huggingface/src/airflow/providers/huggingface/hooks/huggingface.py
index 945bd735711..4933fc96c41 100644
--- 
a/providers/huggingface/src/airflow/providers/huggingface/hooks/huggingface.py
+++ 
b/providers/huggingface/src/airflow/providers/huggingface/hooks/huggingface.py
@@ -45,6 +45,7 @@ class HuggingFaceHook(BaseHook):
     hook_name = "Hugging Face"
 
     def __init__(self, huggingface_conn_id: str | None = default_conn_name) -> 
None:
+        """Initialize the hook with the Airflow connection used for Hub 
access."""
         super().__init__()
         self.huggingface_conn_id = huggingface_conn_id
         self._allow_ambient_fallback = huggingface_conn_id in (None, 
self.default_conn_name)
@@ -64,6 +65,7 @@ class HuggingFaceHook(BaseHook):
         }
 
     def get_token(self) -> str | bool | None:
+        """Return the connection token, ``False`` to disable authentication, 
or ``None`` for SDK fallback."""
         if not self.huggingface_conn_id:
             return None
         try:
@@ -75,11 +77,13 @@ class HuggingFaceHook(BaseHook):
         return connection.password or False
 
     def get_conn(self) -> HfApi:
+        """Return the lazily initialized Hugging Face Hub API client."""
         if self._client is None:
             self._client = HfApi(token=self.get_token())
         return self._client
 
     def test_connection(self) -> tuple[bool, str]:
+        """Check the configured credentials by requesting the authenticated 
user."""
         try:
             self.get_conn().whoami()
             return True, "Connection successfully tested"
@@ -87,6 +91,7 @@ class HuggingFaceHook(BaseHook):
             return False, str(exc)
 
     def load_dataset(self, path: str, **kwargs: Any) -> Any:
+        """Load a dataset with the connection token unless ``token`` is 
explicitly provided."""
         from datasets import load_dataset
 
         token = self.get_token()
@@ -95,6 +100,7 @@ class HuggingFaceHook(BaseHook):
         return load_dataset(path, **kwargs)
 
     def get_dataset_info(self, repo_id: str, revision: str | None = None) -> 
Any:
+        """Return Hub metadata for a dataset repository at the requested 
revision."""
         return self.get_conn().dataset_info(repo_id, revision=revision)
 
     @staticmethod
@@ -150,6 +156,7 @@ class HuggingFaceHook(BaseHook):
         return None
 
     def push_to_hub(self, dataset: Any, repo_id: str, **kwargs: Any) -> Any:
+        """Publish a dataset to the Hub, using the connection token by 
default."""
         token = self.get_token()
         if token is not None and "token" not in kwargs:
             kwargs["token"] = token
diff --git 
a/providers/huggingface/src/airflow/providers/huggingface/operators/datasets.py 
b/providers/huggingface/src/airflow/providers/huggingface/operators/datasets.py
index 55bdd61ebfc..280e2a89384 100644
--- 
a/providers/huggingface/src/airflow/providers/huggingface/operators/datasets.py
+++ 
b/providers/huggingface/src/airflow/providers/huggingface/operators/datasets.py
@@ -354,6 +354,7 @@ class LoadDatasetOperator(BaseOperator):
         durable: bool = True,
         **kwargs: Any,
     ) -> None:
+        """Configure the source dataset and Parquet artifact destination."""
         super().__init__(**kwargs)
         self.path = path
         self.output_uri = output_uri
@@ -368,6 +369,7 @@ class LoadDatasetOperator(BaseOperator):
         self.durable = durable
 
     def execute(self, context: Context) -> dict[str, Any]:
+        """Load the requested dataset revision and write its artifact 
manifest."""
         hook = HuggingFaceHook(self.huggingface_conn_id)
         requested_revision = self.revision
         is_hub_repo = _is_hub_repo(self.path)
@@ -420,6 +422,7 @@ class StreamDatasetOperator(BaseOperator):
 
     @classmethod
     def partial(cls, **kwargs: Any) -> Any:
+        """Declare the publication asset when constructing a mapped 
operator."""
         repo_id = kwargs.get("repo_id")
         if not isinstance(repo_id, str):
             raise ValueError(
@@ -453,6 +456,7 @@ class StreamDatasetOperator(BaseOperator):
         durable: bool = True,
         **kwargs: Any,
     ) -> None:
+        """Configure a streamed source, its transformations, and Hub 
destination."""
         if "{{" in repo_id:
             raise ValueError(
                 "repo_id cannot be templated: it defines the Asset that 
downstream DAGs schedule on."
@@ -480,6 +484,7 @@ class StreamDatasetOperator(BaseOperator):
         super().__init__(outlets=declared_outlets, **kwargs)
 
     def execute(self, context: Context) -> dict[str, Any]:
+        """Stream, transform, and publish the dataset, then return commit 
metadata."""
         hook = HuggingFaceHook(self.huggingface_conn_id)
         is_hub_repo = _is_hub_repo(self.path)
         requested_revision = self.revision
@@ -588,6 +593,7 @@ class StreamDatasetOperator(BaseOperator):
         return result
 
     def _emit_asset_event(self, context: Context, publication: dict[str, Any]) 
-> None:
+        """Attach publication metadata to the successful outlet event."""
         events = context.get("outlet_events")
         if events is not None and self.published_asset is not None:
             events[self.published_asset].extra = {
@@ -615,6 +621,7 @@ class MapDatasetOperator(BaseOperator):
         storage_conn_id: str | None = None,
         **kwargs: Any,
     ) -> None:
+        """Configure an artifact transform and its output location."""
         super().__init__(**kwargs)
         if not callable(transform):
             raise TypeError("transform must be a callable")
@@ -627,6 +634,7 @@ class MapDatasetOperator(BaseOperator):
         self.storage_conn_id = storage_conn_id
 
     def execute(self, context: Context) -> dict[str, Any]:
+        """Apply the transform to the input artifact and save the result."""
         with tempfile.TemporaryDirectory(prefix="airflow-hf-cache-") as 
cache_dir:
             dataset = _load_artifact(
                 self.input_uri,
@@ -651,6 +659,7 @@ class PushToHubOperator(BaseOperator):
 
     @classmethod
     def partial(cls, **kwargs: Any) -> Any:
+        """Declare the publication asset when constructing a mapped 
operator."""
         repo_id = kwargs.get("repo_id")
         if not isinstance(repo_id, str):
             raise ValueError(
@@ -679,6 +688,7 @@ class PushToHubOperator(BaseOperator):
         durable: bool = True,
         **kwargs: Any,
     ) -> None:
+        """Configure the artifact, Hub repository, and publication options."""
         if "{{" in repo_id:
             raise ValueError(
                 "repo_id cannot be templated: it defines the Asset that 
downstream DAGs schedule on."
@@ -698,6 +708,7 @@ class PushToHubOperator(BaseOperator):
         super().__init__(outlets=declared_outlets, **kwargs)
 
     def execute(self, context: Context) -> dict[str, Any]:
+        """Publish the input artifact and return the resulting commit 
metadata."""
         source = self.input_uri if isinstance(self.input_uri, dict) else {}
         fingerprint = source.get("fingerprint")
         if not fingerprint:
@@ -772,6 +783,7 @@ class PushToHubOperator(BaseOperator):
         return result
 
     def _emit_asset_event(self, context: Context, publication: dict[str, Any]) 
-> None:
+        """Attach publication metadata to the successful outlet event."""
         events = context.get("outlet_events")
         if events is not None and self.published_asset is not None:
             events[self.published_asset].extra = {

Reply via email to