Skip to content

Commit

Permalink
Download with pd.read_csv, convert to numpy rec array when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
kongscn committed Jun 18, 2014
1 parent 1ef98e8 commit e53f6f2
Showing 1 changed file with 31 additions and 61 deletions.
92 changes: 31 additions & 61 deletions Quandl/Quandl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e53f6f2

Please sign in to comment.