Skip to content

Add --merge-pull-request option for convert_to_parquet #7556

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion src/datasets/commands/convert_to_parquet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from argparse import ArgumentParser
from typing import Optional

from huggingface_hub import HfApi

import datasets.config
from datasets.commands import BaseDatasetsCLICommand
from datasets.hub import convert_to_parquet

Expand All @@ -11,6 +14,7 @@ def _command_factory(args):
args.token,
args.revision,
args.trust_remote_code,
args.merge_pull_request,
)


Expand All @@ -26,6 +30,11 @@ def register_subcommand(parser):
parser.add_argument(
"--trust_remote_code", action="store_true", help="whether to trust the code execution of the load script"
)
parser.add_argument(
"--merge-pull-request",
action="store_true",
help="whether to automatically merge the pull request after conversion",
)
parser.set_defaults(func=_command_factory)

def __init__(
Expand All @@ -34,13 +43,24 @@ def __init__(
token: Optional[str],
revision: Optional[str],
trust_remote_code: bool,
merge_pull_request: bool,
):
self._dataset_id = dataset_id
self._token = token
self._revision = revision
self._trust_remote_code = trust_remote_code
self._merge_pull_request = merge_pull_request

def run(self) -> None:
_ = convert_to_parquet(
commit_info = convert_to_parquet(
self._dataset_id, revision=self._revision, token=self._token, trust_remote_code=self._trust_remote_code
)

if self._merge_pull_request:
api = HfApi(endpoint=datasets.config.HF_ENDPOINT, token=self._token)
api.merge_pull_request(
repo_id=self._dataset_id,
discussion_num=int(commit_info.pr_num),
token=self._token,
repo_type="dataset",
)