diff --git a/src/nemosis/data_fetch_methods.py b/src/nemosis/data_fetch_methods.py index d61501a..f813a3f 100644 --- a/src/nemosis/data_fetch_methods.py +++ b/src/nemosis/data_fetch_methods.py @@ -69,6 +69,7 @@ def dynamic_data_compiler( parse_data_types (bool): infers data types of columns when reading data. default True for API use. rebuild (bool): If True then cache files are rebuilt + (redownload, re-unzip, re-convert) even if they exist already. False by default. **kwargs: additional arguments passed to the pd.to_{fformat}() function @@ -80,7 +81,9 @@ def dynamic_data_compiler( 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.") + raise UserInputError( + f"The raw_data_location {raw_data_location} provided does not exist." + ) if table_name not in _defaults.dynamic_tables: raise UserInputError("Table name provided is not a dynamic table.") @@ -201,6 +204,7 @@ def cache_compiler( as object type (compatbile with GUI use). For type inference for a cache, use cache_compiler. rebuild (bool): If True then cache files are rebuilt + (redownload, re-unzip, re-convert) even if they exist already. False by default. keep_csv (bool): If True, raw CSVs from AEMO are retained alongside the typed feather/parquet after the @@ -303,7 +307,9 @@ def static_table( 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.") + raise UserInputError( + f"The raw_data_location {raw_data_location} provided does not exist." + ) if table_name not in _defaults.static_tables: raise UserInputError("Table name provided is not a static table.") @@ -801,7 +807,7 @@ def _determine_columns_and_read_csv( def _write_to_format(data, fformat, full_filename, write_kwargs): """ Used by read_data_and_create_file - Writes the DataFrame to a non-CSV format is a non_CSV format is specified. + Writes the DataFrame to a non-CSV format if a non-CSV format is specified. """ write_function = {"feather": data.to_feather, "parquet": data.to_parquet} # Remove files of the same name - deals with case of corrupted files. diff --git a/src/nemosis/downloader.py b/src/nemosis/downloader.py index e333b95..f2b494f 100644 --- a/src/nemosis/downloader.py +++ b/src/nemosis/downloader.py @@ -428,8 +428,8 @@ def download_unzip_csv(url, down_load_to, keep_zip=False): def download_csv(url, path_and_name): """ - This function downloads a zipped csv using a url, - extracts the csv and saves it a specified location + This function downloads a csv using a url, + and saves it to a specified location. """ download_to_path(url, path_and_name) diff --git a/tests/test_errors.py b/tests/test_errors.py index ca44d43..fc23b7f 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -82,6 +82,26 @@ def test_dynamic_raw_data_location_is_none(): ) +def test_dynamic_raw_data_location_missing_includes_path_in_error(tmp_path): + """The "does not exist" error must include the offending path so the + caller can see exactly what they passed (helps diagnose typos and + cwd mistakes). Regression test for the improvement that landed via + the doc-strings-and-error-messages cleanup.""" + bogus = str(tmp_path / "subdir-that-does-not-exist") + with pytest.raises(UserInputError, match="subdir-that-does-not-exist"): + dynamic_data_compiler( + "2018/05/01 00:00:00", "2018/05/01 01:00:00", + "DISPATCHPRICE", raw_data_location=bogus, + ) + + +def test_static_raw_data_location_missing_includes_path_in_error(tmp_path): + """Same regression contract for static_table.""" + bogus = str(tmp_path / "another-missing-dir") + with pytest.raises(UserInputError, match="another-missing-dir"): + static_table("VARIABLES_FCAS_4_SECOND", raw_data_location=bogus) + + # --------------------------------------------------------------------------- # Argument-validation: cache_compiler # ---------------------------------------------------------------------------