1212import warnings
1313try :
1414 import pandas as pd
15+ import numpy as np
1516except ImportError :
1617 "Can't find pandas, won't be able to use the funtions that return dataframes."
1718 pass
@@ -47,11 +48,14 @@ def _calcbench_session():
4748 _SESSION_STUFF ['session' ] = session
4849 return session
4950
50- def _rig_for_testing (domain = 'localhost:444' ):
51+ def _rig_for_testing (domain = 'localhost:444' , suppress_http_warnings = True ):
5152 _SESSION_STUFF ['api_url_base' ] = 'https://' + domain + '/api/{0}'
5253 _SESSION_STUFF ['logon_url' ] = 'https://' + domain + '/account/LogOnAjax'
5354 _SESSION_STUFF ['ssl_verify' ] = False
5455 _SESSION_STUFF ['session' ] = None
56+ if suppress_http_warnings :
57+ from requests .packages .urllib3 .exceptions import InsecureRequestWarning
58+ requests .packages .urllib3 .disable_warnings (InsecureRequestWarning )
5559
5660def _json_POST (end_point , payload ):
5761 url = _SESSION_STUFF ['api_url_base' ].format (end_point )
@@ -111,6 +115,7 @@ def normalized_dataframe(company_identifiers=[],
111115 point_in_time = point_in_time ,
112116 filing_accession_number = filing_accession_number )
113117 if not data :
118+ warnings .warn ("No data found" )
114119 return pd .DataFrame ()
115120 quarterly = start_period and end_period
116121 if quarterly :
@@ -142,9 +147,11 @@ def normalized_dataframe(company_identifiers=[],
142147 except ValueError :
143148 if 'date' in column_name .lower ():
144149 data [column_name ] = pd .to_datetime (data [column_name ], errors = 'coerce' )
145-
150+
151+ for missing_metric in missing_metrics :
152+ data [missing_metric ] = np .nan # We want columns for every requested metric.
146153 data = data .unstack ('ticker' )
147- data = data [[metric for metric in metrics if metric in metrics_found ]]
154+ # data = data[[metric for metric in metrics if metric in metrics_found]] I don't know what this was doing, akittredge August 2016
148155
149156 return data
150157
@@ -155,7 +162,7 @@ def _build_quarter_period(data_point):
155162
156163def _build_annual_period (data_point ):
157164 data_point .pop ('calendar_period' )
158- return pd .Period (year = data_point .pop ('calendar_year' ), freq = 'a' )
165+ return pd .Period (year = data_point .pop ('calendar_year' ), freq = 'a' )
159166
160167normalized_data = normalized_dataframe # used to call it normalized_data.
161168
@@ -225,6 +232,22 @@ def normalized_raw(company_identifiers=[],
225232 }
226233 return _json_POST ("NormalizedValues" , payload )
227234
235+ def point_in_time (company_identifiers = [], all_footnotes = False ):
236+ '''
237+ Just for point-in-time footnotes now.
238+ '''
239+ data = mapped_raw (company_identifiers = company_identifiers ,
240+ all_footnotes = all_footnotes ,
241+ point_in_time = True )
242+ return pd .DataFrame (data )
243+
244+ def mapped_raw (company_identifiers = [], all_footnotes = False , point_in_time = False ):
245+ payload = {
246+ 'companiesParameters' : {'companyIdentifiers' : company_identifiers },
247+ 'periodParameters' : {},
248+ 'pageParameters' : {'pointInTime' : point_in_time , 'allFootnotes' : all_footnotes }
249+ }
250+ return _json_POST ("mappedData" , payload )
228251
229252def as_reported_raw (company_identifier ,
230253 statement_type ,
@@ -432,12 +455,13 @@ def filings(company_identifier, include_non_xbrl=True):
432455 return r .json ()
433456
434457if __name__ == '__main__' :
435- _rig_for_testing ()
436- dow = tickers (index = 'DJIA' )
437- normalized_dataframe (company_identifiers = dow ,
438- metrics = ['filing_date' , ' revenue' , 'marketcapatendofperiod ' ],
458+ # _rig_for_testing()
459+ # dow = tickers(index='DJIA')
460+ normalized_dataframe (company_identifiers = [ 'msft' , 'twtr' ] ,
461+ metrics = ['revenue' , 'tradingsecurities ' ],
439462 start_year = 2009 , start_period = 0 ,
440463 end_year = 2016 , end_period = 0 )
464+ exit ()
441465 print (text_search (company_identifiers = ['msft' ], full_text_search_term = 'revenue' , year = 2014 , period = 0 ))
442466
443467 data = normalized_data (entire_universe = True ,
0 commit comments