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

Fix push_to_hub by not calling create_branch if PR branch #7069

Merged
merged 6 commits into from
Jul 30, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/datasets/arrow_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5677,7 +5677,8 @@ def push_to_hub(
)
repo_id = repo_url.repo_id

if revision is not None:
if revision is not None and not revision.startswith("refs/pr/"):
# We do not call create_branch for a PR reference: 400 Bad Request
api.create_branch(repo_id, branch=revision, token=token, repo_type="dataset", exist_ok=True)

if not data_dir:
Expand Down
3 changes: 2 additions & 1 deletion src/datasets/dataset_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,8 @@ def push_to_hub(
)
repo_id = repo_url.repo_id

if revision is not None:
if revision is not None and not revision.startswith("refs/pr/"):
# We do not call create_branch for a PR reference: 400 Bad Request
api.create_branch(repo_id, branch=revision, token=token, repo_type="dataset", exist_ok=True)

if not data_dir:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ def test_convert_to_parquet(temporary_repo, hf_api, hf_token, ci_hub_config, ci_
_ = convert_to_parquet(repo_id, token=hf_token, trust_remote_code=True)
# mock_create_branch
assert mock_create_branch.called
assert mock_create_branch.call_count == 2
for call_args, expected_branch in zip(mock_create_branch.call_args_list, ["refs/pr/1", "script"]):
assert call_args.kwargs.get("branch") == expected_branch
assert mock_create_branch.call_count == 1
assert mock_create_branch.call_args.kwargs.get("branch") == "script"
# mock_create_commit
assert mock_create_commit.called
assert mock_create_commit.call_count == 2
Expand Down
Loading