SimFin / simfin

Simple financial data for Python
https://simfin.com/
Other
298 stars 39 forks source link

Feature suggestion: better error handling in case sf.set_data_dir is omitted #3

Closed thf24 closed 4 years ago

thf24 commented 4 years ago

Description

If the line sf.set_data_dir is omitted, the following error is raised:

TypeError: expected str, bytes or os.PathLike object, not NoneType

This error is very cryptic and it's not clear for the user that the explicit setting of the data path is missing. A solution would be to either display an error message like: Error: Data directory not specified, please specify a data directory using sf.set_data_dir OR select the home directory of the user by default (and append simfin_data) if no data directory is specified explicitely:

from pathlib import Path
import os
home = str(Path.home())
default_directory = os.path.join(home, "simfin_data")

Full Code to Reproduce Error

import pandas as pd

# Import the main functionality from the SimFin Python API.
import simfin as sf

# Import names used for easy access to SimFin's data-columns.
from simfin.names import *

df1 = sf.load(dataset='income', variant='annual', market='us')
Hvass-Labs commented 4 years ago

Fixed by adding a check in config.py whether the data-dir has been set.