forked from quandl/quandl-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download with pd.read_csv, convert to numpy rec array when necessary
- Loading branch information
Showing
1 changed file
with
31 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,69 +92,39 @@ def get(dataset, **kwargs): | |
trim_start=trim_start, | ||
trim_end=trim_end, | ||
**kwargs) | ||
|
||
#Determine format data is retrieved in | ||
if returns == 'numpy': | ||
try: | ||
u = urlopen(url) | ||
try: | ||
array = genfromtxt(u, names=True, delimiter=',', dtype=None) | ||
except ValueError as e: | ||
error = "Currently we only support multisets with up to 100 columns. Please contact [email protected] if this is a problem." | ||
raise MultisetLimit(error) | ||
|
||
return array | ||
#Errors | ||
except IOError as e: | ||
print("url:", url) | ||
raise ParsingError("Parsing Error! {}".format(e)) | ||
except HTTPError as e: | ||
#API limit reached | ||
if str(e) == 'HTTP Error 403: Forbidden': | ||
error = 'API daily call limit exceeded. Contact us at [email protected] if you want an increased daily limit' | ||
raise CallLimitExceeded(error) | ||
|
||
#Dataset not found | ||
elif str(e) == 'HTTP Error 404: Not Found': | ||
error = "Dataset not found. Check Quandl code: {} for errors".format(dataset) | ||
raise DatasetNotFound(error) | ||
#Catch all | ||
else: | ||
print("url:", url) | ||
error = "Error Downloading! {}".format(e) | ||
raise ErrorDownloading(error) | ||
else: # assume pandas is requested | ||
try: | ||
urldata = _download(url) | ||
|
||
if urldata.columns.size > 100: | ||
error = "Currently we only support multisets with up to 100 columns. Please contact [email protected] if this is a problem." | ||
raise MultisetLimit(error) | ||
try: | ||
urldata = _download(url) | ||
if urldata.columns.size > 100: | ||
error = "Currently we only support multisets with up to 100 columns. Please contact [email protected] if this is a problem." | ||
raise MultisetLimit(error) | ||
else: | ||
if text == "no": | ||
pass | ||
else: | ||
if text == "no": | ||
pass | ||
else: | ||
print("Returning Dataframe for ", dataset) | ||
return urldata | ||
|
||
|
||
#Error catching | ||
except HTTPError as e: | ||
#API limit reached | ||
if str(e) == 'HTTP Error 403: Forbidden': | ||
error = 'API daily call limit exceeded. Contact us at [email protected] if you want an increased daily limit' | ||
raise CallLimitExceeded(error) | ||
|
||
#Dataset not found | ||
elif str(e) == 'HTTP Error 404: Not Found': | ||
error = "Dataset not found. Check Quandl code: {} for errors".format(dataset) | ||
raise DatasetNotFound(error) | ||
|
||
#Catch all | ||
else: | ||
print("url:", url) | ||
error = "Error Downloading! {}".format(e) | ||
raise ErrorDownloading(error) | ||
print("Returning Dataframe for ", dataset) | ||
|
||
#Error catching | ||
except HTTPError as e: | ||
#API limit reached | ||
if str(e) == 'HTTP Error 403: Forbidden': | ||
error = 'API daily call limit exceeded. Contact us at [email protected] if you want an increased daily limit' | ||
raise CallLimitExceeded(error) | ||
|
||
#Dataset not found | ||
elif str(e) == 'HTTP Error 404: Not Found': | ||
error = "Dataset not found. Check Quandl code: {} for errors".format(dataset) | ||
raise DatasetNotFound(error) | ||
|
||
#Catch all | ||
else: | ||
print("url:", url) | ||
error = "Error Downloading! {}".format(e) | ||
raise ErrorDownloading(error) | ||
|
||
if returns == 'numpy': | ||
return urldata.to_records() | ||
return urldata | ||
|
||
def push(data, code, name, authtoken='', desc='', override=False,text='yes'): | ||
''' Upload a pandas Dataframe to Quandl and returns link to the dataset. | ||
|