Skip to content

Commit

Permalink
changed FRED download code;
Browse files Browse the repository at this point in the history
see GH issue #157
now it goes through requests instead of using
pd.read_csv(endpoint) directly; should have no
effect on performance but it seems requests is
more robust in handling ssl (should use certifi)
  • Loading branch information
enzbus committed May 11, 2024
1 parent bc1bce1 commit 710317b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cvxportfolio/data/symbol_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import logging
import sqlite3
import warnings
from io import StringIO
from pathlib import Path
from pickle import UnpicklingError
from urllib.error import URLError
Expand Down Expand Up @@ -1087,10 +1088,11 @@ class Fred(SymbolData):

def _internal_download(self, symbol):
try:
_downloaded = requests.get(self.URL + f'?id={symbol}', timeout=10)
_csv = StringIO(_downloaded.text)
return pd.to_numeric(pd.read_csv(
self.URL + f'?id={symbol}',
index_col=0, parse_dates=[0])[symbol], errors='coerce')
except URLError as exc:
_csv, index_col=0, parse_dates=[0])[symbol], errors='coerce')
except requests.ConnectionError as exc:
raise DataError(f"Download of {symbol}"
+ f" from {self.__class__.__name__} failed."
+ " Are you connected to the Internet?") from exc
Expand Down

0 comments on commit 710317b

Please sign in to comment.