-
Notifications
You must be signed in to change notification settings - Fork 375
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
Delete the downloaded zip and folder in retrieve_dataset
#2150
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,11 @@ | |
# Licensed under the MIT License. | ||
|
||
import os | ||
import shutil | ||
import uuid | ||
|
||
DOWNLOADED_DATASET_DIR = 'datasets.4.27.2021' | ||
|
||
|
||
def is_valid_uuid(id: str): | ||
"""Check if the given id is a valid uuid. | ||
|
@@ -29,7 +32,7 @@ def retrieve_dataset(dataset, **kwargs): | |
:rtype: object | ||
""" | ||
# if data not extracted, download zip and extract | ||
outdirname = 'datasets.4.27.2021' | ||
outdirname = DOWNLOADED_DATASET_DIR | ||
if not os.path.exists(outdirname): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the dataset is downloaded we don't re-download it here... we just re-use the downloaded one |
||
try: | ||
from urllib import urlretrieve | ||
|
@@ -48,17 +51,21 @@ def retrieve_dataset(dataset, **kwargs): | |
if extension == '.npz': | ||
# sparse format file | ||
from scipy.sparse import load_npz | ||
return load_npz(filepath) | ||
in_memory_dataset = load_npz(filepath) | ||
elif extension == '.svmlight': | ||
from sklearn import datasets | ||
return datasets.load_svmlight_file(filepath) | ||
in_memory_dataset = datasets.load_svmlight_file(filepath) | ||
elif extension == '.json': | ||
import json | ||
with open(filepath, encoding='utf-8') as f: | ||
dataset = json.load(f) | ||
return dataset | ||
in_memory_dataset = json.load(f) | ||
elif extension == '.csv': | ||
import pandas as pd | ||
return pd.read_csv(filepath, **kwargs) | ||
in_memory_dataset = pd.read_csv(filepath, **kwargs) | ||
else: | ||
raise Exception('Unrecognized file extension: ' + extension) | ||
|
||
shutil.rmtree(outdirname) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't this increase network calls and also chance tests fail due to networking issues? also I think this might increase test time a lot? we currently just re-use the downloaded file in all test cases instead of re-downloading it every time |
||
os.remove(zipfilename) | ||
|
||
return in_memory_dataset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems oddly specific. Isn't it going to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use a specific zip folder with the date it was created for these datasets (that are put on our blob storage for tests)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so if the dataset changes this need to be updated. How will we remember?