Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/nemosis/data_fetch_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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.")

Expand Down
24 changes: 24 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -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
# ---------------------------------------------------------------------------
Expand All @@ -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
# ---------------------------------------------------------------------------
Expand Down
Loading