From e8fdc79ce773acafc7009a8f28924c12dd5a15b1 Mon Sep 17 00:00:00 2001 From: Charles Allderman Date: Thu, 13 Sep 2018 17:19:21 +0200 Subject: [PATCH] added error catching for null data returned --- pyiress/pyiress.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/pyiress/pyiress.py b/pyiress/pyiress.py index 44738b1..d64be1a 100644 --- a/pyiress/pyiress.py +++ b/pyiress/pyiress.py @@ -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'): @@ -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 @@ -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