Skip to content

Commit

Permalink
added error catching for null data returned
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Allderman committed Sep 13, 2018
1 parent ddaac3f commit e8fdc79
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions pyiress/pyiress.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,13 @@ def time_series(self,ticker,exchange,start_date,end_date,freq='daily',fields=[])
part_date=start_date
data=pd.DataFrame()
while part_date < pd.Timestamp(end_date):
new_data=self._time_series(ticker,exchange,part_date,end_date,freq)
data=pd.concat([data,new_data])
part_date = data.index.max() + pd.DateOffset(1,'D')
try:
new_data=self._time_series(ticker,exchange,part_date,end_date,freq)
data=pd.concat([data,new_data])
part_date = data.index.max() + pd.DateOffset(1,'D')
except:
break

return data

def dividends(self,ticker,exchange,start_date,end_date,freq=None,index_on='ExDividendDate'):
Expand All @@ -174,11 +178,15 @@ def dividends(self,ticker,exchange,start_date,end_date,freq=None,index_on='ExDiv
} }

inputs={**self.header, **parameters}
res=self.client.service.SecurityDividendGetBySecurity(Input=inputs)
data=zeep.helpers.serialize_object(res.Result.DataRows.DataRow)
df=pd.DataFrame(data)
df[index_on]=pd.to_datetime(df[index_on])
df=df.set_index(index_on)

try:
res=self.client.service.SecurityDividendGetBySecurity(Input=inputs)
data=zeep.helpers.serialize_object(res.Result.DataRows.DataRow)
df=pd.DataFrame(data)
df[index_on]=pd.to_datetime(df[index_on])
df=df.set_index(index_on)
except:
df=pd.DataFrame()

return df

Expand Down Expand Up @@ -247,11 +255,12 @@ def get_many(self,data_type,tickers,exchange,start_date,end_date,freq='daily'):
method_to_call = getattr(self, data_type)
for ticker in tickers:
data=method_to_call(ticker,exchange,start_date,end_date,freq)
data=data.reset_index()
data['ticker']=ticker
data['exchange']=exchange
data=data.set_index([date_field[data_type],'ticker'])
data_list.append(data)
if len(data)>0:
data=data.reset_index()
data['ticker']=ticker
data['exchange']=exchange
data=data.set_index([date_field[data_type],'ticker'])
data_list.append(data)
df_data=pd.concat(data_list)
return df_data

Expand Down

0 comments on commit e8fdc79

Please sign in to comment.