diff --git a/src/nemosis/data_fetch_methods.py b/src/nemosis/data_fetch_methods.py index 8e06a67..008b07f 100644 --- a/src/nemosis/data_fetch_methods.py +++ b/src/nemosis/data_fetch_methods.py @@ -63,6 +63,10 @@ def dynamic_data_compiler( Returns: all_data (pd.Dataframe): All data concatenated. """ + + if raw_data_location is None: + raise UserInputError("The raw_data_location provided is None.") + if not _os.path.isdir(raw_data_location): raise UserInputError("The raw_data_location provided does not exist.") @@ -186,6 +190,10 @@ def cache_compiler( Returns: Nothing """ + + if raw_data_location is None: + raise UserInputError("The raw_data_location provided is None.") + if not _os.path.isdir(raw_data_location): raise UserInputError("The raw_data_location provided does not exist.") @@ -262,6 +270,9 @@ def static_table( Returns: data (pd.Dataframe) """ + if raw_data_location is None: + raise UserInputError("The raw_data_location provided is None.") + if not _os.path.isdir(raw_data_location): raise UserInputError("The raw_data_location provided does not exist.") diff --git a/tests/test_errors.py b/tests/test_errors.py index f2b6bdb..ca44d43 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -71,6 +71,17 @@ def test_dynamic_select_columns_all_requires_csv(nemosis_fixture): ) +def test_dynamic_raw_data_location_is_none(): + """Passing None as the cache path is a common caller mistake (forgot + to set it, config returned None). Reject with UserInputError rather + than the cryptic TypeError that os.path.isdir(None) would raise.""" + with pytest.raises(UserInputError, match="is None"): + dynamic_data_compiler( + "2018/05/01 00:00:00", "2018/05/01 01:00:00", + "DISPATCHPRICE", raw_data_location=None, + ) + + # --------------------------------------------------------------------------- # Argument-validation: cache_compiler # --------------------------------------------------------------------------- @@ -102,6 +113,14 @@ def test_cache_select_columns_requires_rebuild(nemosis_fixture): ) +def test_cache_raw_data_location_is_none(): + with pytest.raises(UserInputError, match="is None"): + cache_compiler( + "2018/05/01 00:00:00", "2018/05/01 01:00:00", + "DISPATCHPRICE", raw_data_location=None, + ) + + # --------------------------------------------------------------------------- # Argument-validation: static_table # --------------------------------------------------------------------------- @@ -121,6 +140,11 @@ def test_static_filter_col_not_in_select_columns(nemosis_fixture): ) +def test_static_raw_data_location_is_none(): + with pytest.raises(UserInputError, match="is None"): + static_table("VARIABLES_FCAS_4_SECOND", raw_data_location=None) + + # --------------------------------------------------------------------------- # Network / availability: NoDataToReturn # ---------------------------------------------------------------------------