Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Move dataset card creation to method for easier overriding #6988

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/datasets/arrow_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5781,9 +5781,9 @@ def push_to_hub(
CommitOperationAdd(path_in_repo=config.DATASETDICT_INFOS_FILENAME, path_or_fileobj=buffer)
)
# push to README
DatasetInfosDict({config_name: info_to_dump}).to_dataset_card_data(dataset_card_data)
MetadataConfigs({config_name: metadata_config_to_dump}).to_dataset_card_data(dataset_card_data)
dataset_card = DatasetCard(f"---\n{dataset_card_data}\n---\n") if dataset_card is None else dataset_card
dataset_card = self._create_dataset_card(
dataset_card_data, dataset_card, config_name, info_to_dump, metadata_config_to_dump
)
additions.append(
CommitOperationAdd(path_in_repo=config.REPOCARD_FILENAME, path_or_fileobj=str(dataset_card).encode())
)
Expand Down Expand Up @@ -5826,6 +5826,21 @@ def push_to_hub(
)
return commit_info

def _create_dataset_card(
self,
dataset_card_data: DatasetCardData,
dataset_card: Optional[DatasetCard],
config_name: str,
info_to_dump: DatasetInfo,
metadata_config_to_dump: MetadataConfigs,
) -> DatasetCard:
if dataset_card:
return dataset_card

DatasetInfosDict({config_name: info_to_dump}).to_dataset_card_data(dataset_card_data)
MetadataConfigs({config_name: metadata_config_to_dump}).to_dataset_card_data(dataset_card_data)
return DatasetCard(f"---\n{dataset_card_data}\n---\n")

@transmit_format
@fingerprint_transform(inplace=False)
def add_column(self, name: str, column: Union[list, np.array], new_fingerprint: str):
Expand Down
21 changes: 18 additions & 3 deletions src/datasets/dataset_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,9 +1820,9 @@ def push_to_hub(
CommitOperationAdd(path_in_repo=config.DATASETDICT_INFOS_FILENAME, path_or_fileobj=buffer)
)
# push to README
DatasetInfosDict({config_name: info_to_dump}).to_dataset_card_data(dataset_card_data)
MetadataConfigs({config_name: metadata_config_to_dump}).to_dataset_card_data(dataset_card_data)
dataset_card = DatasetCard(f"---\n{dataset_card_data}\n---\n") if dataset_card is None else dataset_card
dataset_card = self._create_dataset_card(
dataset_card_data, dataset_card, config_name, info_to_dump, metadata_config_to_dump
)
additions.append(
CommitOperationAdd(path_in_repo=config.REPOCARD_FILENAME, path_or_fileobj=str(dataset_card).encode())
)
Expand Down Expand Up @@ -1865,6 +1865,21 @@ def push_to_hub(
)
return commit_info

def _create_dataset_card(
self,
dataset_card_data: DatasetCardData,
dataset_card: Optional[DatasetCard],
config_name: str,
info_to_dump: DatasetInfo,
metadata_config_to_dump: MetadataConfigs,
) -> DatasetCard:
if dataset_card:
return dataset_card

DatasetInfosDict({config_name: info_to_dump}).to_dataset_card_data(dataset_card_data)
MetadataConfigs({config_name: metadata_config_to_dump}).to_dataset_card_data(dataset_card_data)
return DatasetCard(f"---\n{dataset_card_data}\n---\n")


class IterableDatasetDict(dict):
def __repr__(self):
Expand Down
Loading