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

Remove unnecessary 'r' arg in #3661

Merged
merged 1 commit into from
Feb 7, 2022
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
Remove unnecessary 'r' arg in
  • Loading branch information
bryant1410 committed Feb 1, 2022
commit a25b2984d2866762a0557d9b45fa4106808740ca
4 changes: 2 additions & 2 deletions .github/hub/update_hub_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def check_authorizations(user_info: dict):

def apply_hacks_for_moon_landing(dataset_repo_path: Path):
if (dataset_repo_path / "README.md").is_file():
with (dataset_repo_path / "README.md").open("r") as f:
with (dataset_repo_path / "README.md").open() as f:
readme_content = f.read()
if readme_content.count("---\n") > 1:
_, tags, content = readme_content.split("---\n", 2)
Expand Down Expand Up @@ -185,7 +185,7 @@ def __call__(self, dataset_name: str) -> bool:
datasets_lib_path = Path(os.environ["DATASETS_LIB_PATH"]).expanduser().resolve()

if Path(token).expanduser().is_file():
with Path(token).expanduser().open("r") as f:
with Path(token).expanduser().open() as f:
token = f.read().strip()
user_info = whoami(token)
check_authorizations(user_info)
Expand Down
6 changes: 3 additions & 3 deletions datasets/evidence_infer_treatment/evidence_infer_treatment.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ def _split_generators(self, dl_manager):
SPLITS = {}
for split in ["train", "test", "validation"]:
filename = os.path.join(dl_dir, "splits", f"{split}_article_ids.txt")
with open(filename, "r", encoding="utf-8") as f:
with open(filename, encoding="utf-8") as f:
for line in f:
id_ = int(line.strip())
SPLITS[id_] = split

ALL_PROMPTS = {}
prompts_filename = os.path.join(dl_dir, "prompts_merged.csv")
with open(prompts_filename, "r", encoding="utf-8") as f:
with open(prompts_filename, encoding="utf-8") as f:
data = csv.DictReader(f)
for item in data:
prompt_id = int(item["PromptID"])
ALL_PROMPTS[prompt_id] = {"Prompt": item, "Annotations": []}

annotations_filename = os.path.join(dl_dir, "annotations_merged.csv")
with open(annotations_filename, "r", encoding="utf-8") as f:
with open(annotations_filename, encoding="utf-8") as f:
data = csv.DictReader(f)
for item in data:
prompt_id = int(item["PromptID"])
Expand Down
6 changes: 3 additions & 3 deletions datasets/timit_asr/timit_asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def _generate_examples(self, data_info_csv):
wav_path = os.path.join(data_path, *(audio_data["path_from_data_dir"].split("/")))

# extract transcript
with open(wav_path.replace(".WAV", ".TXT"), "r", encoding="utf-8") as op:
with open(wav_path.replace(".WAV", ".TXT"), encoding="utf-8") as op:
transcript = " ".join(op.readlines()[0].split()[2:]) # first two items are sample number

# extract phonemes
with open(wav_path.replace(".WAV", ".PHN"), "r", encoding="utf-8") as op:
with open(wav_path.replace(".WAV", ".PHN"), encoding="utf-8") as op:
phonemes = [
{
"start": i.split(" ")[0],
Expand All @@ -152,7 +152,7 @@ def _generate_examples(self, data_info_csv):
]

# extract words
with open(wav_path.replace(".WAV", ".WRD"), "r", encoding="utf-8") as op:
with open(wav_path.replace(".WAV", ".WRD"), encoding="utf-8") as op:
words = [
{
"start": i.split(" ")[0],
Expand Down
2 changes: 1 addition & 1 deletion tests/features/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def _split_generators(self, dl_manager):
]

def _generate_examples(self, filepath, **kwargs):
with open(filepath, "r", encoding="utf-8") as f:
with open(filepath, encoding="utf-8") as f:
for i, line in enumerate(f):
image_path, caption = line.split(",")
yield i, {"image": image_path.strip(), "caption": caption.strip()}
Expand Down