From 378636910375a31d9144320521e87b53b872318e Mon Sep 17 00:00:00 2001 From: daniel-wells Date: Sun, 6 Feb 2022 14:04:39 +0000 Subject: [PATCH] fix TypeError when no price is returned Sometimes the yahoo source will return None as a price (I think due to the date being too recent), this will result in a TypeError "conversion from NoneType to Decimal is not supported" when conversion of the price to a Decimal is attempted. --- beanprice/sources/yahoo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beanprice/sources/yahoo.py b/beanprice/sources/yahoo.py index 1dd1c71..dea03a2 100644 --- a/beanprice/sources/yahoo.py +++ b/beanprice/sources/yahoo.py @@ -100,7 +100,7 @@ def get_price_series(ticker: str, timestamp_array = result['timestamp'] close_array = result['indicators']['quote'][0]['close'] series = [(datetime.fromtimestamp(timestamp, tz=tzone), Decimal(price)) - for timestamp, price in zip(timestamp_array, close_array)] + for timestamp, price in zip(timestamp_array, close_array) if price is not None] currency = result['meta']['currency'] return series, currency