Skip to content

Commit

Permalink
Fixed kaggle function (#1531)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadam-Tushar committed Jan 29, 2021
1 parent 7edbec3 commit 510c4e2
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions retriever/lib/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,34 +533,30 @@ def download_from_kaggle(

api = KaggleApi()
api.authenticate()
archive_full_path = archive_full_path + ".zip"

if data_source == "dataset":
archive_full_path = archive_full_path + ".zip"
try:
api.dataset_download_files(dataset=dataset_name,
path=archive_dir,
quiet=False,
force=True)
file_names = self.extract_zip(archive_full_path, archive_dir)
except ApiException:
print(f"The dataset '{dataset_name}' isn't currently available "
f"in the Retriever.\nRun 'retriever ls' to see a "
f"list of currently available datasets.")
except ApiException as e:
print(f"Could not download '{dataset_name}' from kaggle datasets.")
print("Response :", e.body.decode("unicode_escape"))
return []

else:
archive_full_path = archive_full_path.replace("kaggle:competition:",
"") + ".zip"
try:
api.competition_download_files(competition=dataset_name,
path=archive_dir,
quiet=False,
force=True)
file_names = self.extract_zip(archive_full_path, archive_dir)
except ApiException:
print(f"The dataset '{dataset_name}' isn't currently available "
f"in the Retriever.\nRun 'retriever ls' to see a "
f"list of currently available datasets.")
except ApiException as e:
print(f"Could not download '{dataset_name}' from kaggle competitions.")
print("Response :", e.body.decode("unicode_escape"))
return []

return file_names
Expand Down Expand Up @@ -589,8 +585,7 @@ def download_files_from_archive(
archive_dir = archive_dir.format(dataset=self.script.name)
if not os.path.exists(archive_dir):
os.makedirs(archive_dir)

if hasattr(self.script.__dict__, "kaggle"):
if hasattr(self.script, "kaggle"):
file_names = self.download_from_kaggle(data_source=self.script.data_source,
dataset_name=url,
archive_dir=archive_dir,
Expand Down

0 comments on commit 510c4e2

Please sign in to comment.