Skip to content

Commit 5c33306

Browse files
refactor: improve code readability and formatting in Hugging Face integration files
- Reformatted dictionary comprehension for better readability in `HuggingFaceHubClient`. - Consolidated multiple lines into a single line for downloading processor datasets and artifacts. - Streamlined logging message formatting in `_load_column_config` function. - Removed unnecessary blank lines in various files to enhance code cleanliness.
1 parent d1b39a7 commit 5c33306

5 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/data_designer/integrations/huggingface/client.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,10 @@ def _build_column_stats_by_type(self, analysis: DatasetProfilerResults) -> dict[
652652
except (ValueError, TypeError):
653653
continue
654654

655-
return {col_type: [pydantic_to_dict(stat) for stat in stats_list] for col_type, stats_list in column_stats_by_type.items()}
655+
return {
656+
col_type: [pydantic_to_dict(stat) for stat in stats_list]
657+
for col_type, stats_list in column_stats_by_type.items()
658+
}
656659

657660
def _sort_column_types(self, column_stats_by_type: dict[str, list[dict[str, Any]]]) -> list[str]:
658661
"""Sort column types by display order.
@@ -857,12 +860,8 @@ def _load_processors_from_hub(
857860
processor_files = [f for f in repo_files if f.startswith("processors/")]
858861

859862
processor_groups = HuggingFaceHubClient._group_processor_files(processor_files)
860-
processor_datasets = HuggingFaceHubClient._download_processor_datasets(
861-
repo_id, token, processor_groups
862-
)
863-
processor_artifacts = HuggingFaceHubClient._download_processor_artifacts(
864-
repo_id, token, processor_groups
865-
)
863+
processor_datasets = HuggingFaceHubClient._download_processor_datasets(repo_id, token, processor_groups)
864+
processor_artifacts = HuggingFaceHubClient._download_processor_artifacts(repo_id, token, processor_groups)
866865

867866
return processor_datasets or None, processor_artifacts or None
868867
except (HfHubHTTPError, FileNotFoundError, Exception):

src/data_designer/integrations/huggingface/hub_results.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ class HubDatasetResults:
4040

4141
model_configs: list[dict[str, Any]] | None = None
4242
"""Model configurations if available."""
43-

src/data_designer/integrations/huggingface/reconstruction.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,5 @@ def _load_column_config(
266266
try:
267267
return config_class.model_validate(col_config_dict)
268268
except Exception as e:
269-
logger.warning(
270-
f"Failed to load column config '{col_config_dict.get('name', 'unknown')}': {e}. Skipping."
271-
)
269+
logger.warning(f"Failed to load column config '{col_config_dict.get('name', 'unknown')}': {e}. Skipping.")
272270
return None

src/data_designer/interface/huggingface/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@
1515
HuggingFaceHubMixin = HuggingFaceHubClient
1616

1717
__all__ = ["HuggingFaceHubMixin", "HuggingFaceHubClient", "pull_from_hub", "HubDatasetResults", "resolve_hf_token"]
18-

tests/integrations/huggingface/test_client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def test_build_sample_records_empty(self, client: HuggingFaceHubClient) -> None:
321321

322322
def test_build_config_types_summary(self, client: HuggingFaceHubClient) -> None:
323323
"""Test building config types summary."""
324+
324325
class Config1:
325326
pass
326327

@@ -352,9 +353,11 @@ def test_pull_from_hub_basic(
352353
mock_hf_dataset.to_pandas.return_value = pd.DataFrame({"col1": [1, 2, 3]})
353354
mock_load_dataset.return_value = mock_hf_dataset
354355

355-
with patch.object(HuggingFaceHubClient, "_load_analysis_from_hub", return_value=None), patch.object(
356-
HuggingFaceHubClient, "_load_processors_from_hub", return_value=(None, None)
357-
), patch.object(HuggingFaceHubClient, "_load_configs_from_hub", return_value=(None, None, None)):
356+
with (
357+
patch.object(HuggingFaceHubClient, "_load_analysis_from_hub", return_value=None),
358+
patch.object(HuggingFaceHubClient, "_load_processors_from_hub", return_value=(None, None)),
359+
patch.object(HuggingFaceHubClient, "_load_configs_from_hub", return_value=(None, None, None)),
360+
):
358361
result = HuggingFaceHubClient.pull_from_hub(
359362
"test-user/test-dataset",
360363
token="test-token",

0 commit comments

Comments
 (0)