File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed
Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -762,6 +762,18 @@ def test_info(self):
762762 self .assertIn ("symbol" , data .keys (), f"Did not find expected key '{ k } ' in info dict" )
763763 self .assertEqual (self .symbols [0 ], data ["symbol" ], "Wrong symbol value in info dict" )
764764
765+ def test_complementary_info (self ):
766+ # This test is to check that we can successfully retrieve the trailing PEG ratio
767+
768+ # We don't expect this one to have a trailing PEG ratio
769+ data1 = self .tickers [0 ].info
770+ self .assertEqual (data1 ['trailingPegRatio' ], None )
771+
772+ # This one should have a trailing PEG ratio
773+ data2 = self .tickers [2 ].info
774+ self .assertEqual (data2 ['trailingPegRatio' ], 1.2713 )
775+ pass
776+
765777 # def test_fast_info_matches_info(self):
766778 # fast_info_keys = set()
767779 # for ticker in self.tickers:
Original file line number Diff line number Diff line change @@ -718,14 +718,12 @@ def _fetch_complementary(self, proxy):
718718
719719 json_str = self ._data .cache_get (url = url , proxy = proxy ).text
720720 json_data = json .loads (json_str )
721- try :
722- key_stats = json_data ["timeseries" ]["result" ][0 ]
723- if k not in key_stats :
724- # Yahoo website prints N/A, indicates Yahoo lacks necessary data to calculate
725- v = None
721+ if json_data ["timeseries" ]["error" ] is not None :
722+ raise YFinanceException ("Failed to parse json response from Yahoo Finance: " + json_data ["error" ])
723+ for k in keys :
724+ keydict = json_data ["timeseries" ]["result" ][0 ]
725+ if k in keydict :
726+ self ._info [k ] = keydict [k ][- 1 ]["reportedValue" ]["raw" ]
726727 else :
727- # Select most recent (last) raw value in list:
728- v = key_stats [k ][- 1 ]["reportedValue" ]["raw" ]
729- except Exception :
730- v = None
731- self ._info [k ] = v
728+ self .info [k ] = None
729+
You can’t perform that action at this time.
0 commit comments