Skip to content

Commit

Permalink
Implement error handling for database query in make_targets_yf.py
Browse files Browse the repository at this point in the history
Enhanced the data retrieval process from 'price_table' by wrapping the pd.read_sql query in a try-except block. This change aims to improve the robustness of the script against potential runtime errors during the database query execution. Additionally, a pylint directive was added to ignore the broad exception warning, acknowledging the intentional catch-all exception handling approach.
  • Loading branch information
KuiMing committed Mar 19, 2024
1 parent dba93d0 commit b8a128f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion make_targets_yf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@

CONN = sqlite3.connect("price.sqlite")
DATE = (datetime.now() - timedelta(days=365 * 2)).strftime("%Y-%m-%d")
ALL_DATA = pd.read_sql(f"SELECT * FROM price_table where Date>='{DATE}'", CONN)
try:
ALL_DATA = pd.read_sql(f"SELECT * FROM price_table where Date>='{DATE}'", CONN)
# pylint: disable=broad-exception-caught
except Exception:
pass
# OLD_DATA = pickle.load(open("df_20240228.pkl", "rb"))


Expand Down

0 comments on commit b8a128f

Please sign in to comment.