Skip to content

Commit

Permalink
Update error message when kedro-datasets is not installed or `DataS…
Browse files Browse the repository at this point in the history
…et` spelling is used (#3952)

* Update error message when kedro-datasets is not installed

Signed-off-by: Ankita Katiyar <[email protected]>

* Release notes, update error hint

Signed-off-by: Ankita Katiyar <[email protected]>

* Skip test for python 3.8

Signed-off-by: Ankita Katiyar <[email protected]>

* Ignore test coverage

Signed-off-by: Ankita Katiyar <[email protected]>

---------

Signed-off-by: Ankita Katiyar <[email protected]>
Signed-off-by: Ankita Katiyar <[email protected]>
  • Loading branch information
ankatiyar authored Jun 19, 2024
1 parent ff133a5 commit 1c95627
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## Bug fixes and other changes
* Updated error message for invalid catalog entries.
* Updated error message for catalog entries when the dataset class is not found with hints on how to resolve the issue.
* Fixed a bug in the `DataCatalog` `shallow_copy()` method to ensure it returns the type of the used catalog and doesn't cast it to `DataCatalog`.

## Breaking changes to the API
Expand Down
20 changes: 18 additions & 2 deletions kedro/io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def from_config(
except Exception as exc:
raise DatasetError(
f"An exception occurred when parsing config "
f"for dataset '{name}':\n{str(exc)}."
f"for dataset '{name}':\n{str(exc)}"
) from exc

try:
Expand Down Expand Up @@ -406,7 +406,23 @@ def parse_dataset_definition(
class_obj = tmp
break
else:
raise DatasetError(f"Class '{dataset_type}' not found, is this a typo?")
hint = ""
if "DataSet" in dataset_type:
hint = ( # pragma: no cover # To remove when we drop support for python 3.8
"Hint: If you are trying to use a dataset from `kedro-datasets`>=2.0.0, "
"make sure that the dataset name uses the `Dataset` spelling instead of `DataSet`."
)
else:
hint = (
"Hint: If you are trying to use a dataset from `kedro-datasets`, "
"make sure that the package is installed in your current environment. "
"You can do so by running `pip install kedro-datasets` or "
"`pip install kedro-datasets[<dataset-group>]` to install `kedro-datasets` along with "
"related dependencies for the specific dataset group."
)
raise DatasetError(
f"Class '{dataset_type}' not found, is this a typo?" f"\n{hint}"
)

if not class_obj:
class_obj = dataset_type
Expand Down
20 changes: 19 additions & 1 deletion tests/io/test_data_catalog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import re
import sys
from copy import deepcopy
from datetime import datetime, timezone
from pathlib import Path
Expand Down Expand Up @@ -503,7 +504,24 @@ def test_config_missing_class(self, sane_config):

pattern = (
"An exception occurred when parsing config for dataset 'boats':\n"
"Class 'kedro.io.CSVDatasetInvalid' not found"
"Class 'kedro.io.CSVDatasetInvalid' not found, is this a typo?"
)
with pytest.raises(DatasetError, match=re.escape(pattern)):
DataCatalog.from_config(**sane_config)

@pytest.mark.skipif(
sys.version_info < (3, 9),
reason="for python 3.8 kedro-datasets version 1.8 is used which has the old spelling",
)
def test_config_incorrect_spelling(self, sane_config):
"""Check hint if the type uses the old DataSet spelling"""
sane_config["catalog"]["boats"]["type"] = "pandas.CSVDataSet"

pattern = (
"An exception occurred when parsing config for dataset 'boats':\n"
"Class 'pandas.CSVDataSet' not found, is this a typo?"
"\nHint: If you are trying to use a dataset from `kedro-datasets`>=2.0.0,"
" make sure that the dataset name uses the `Dataset` spelling instead of `DataSet`."
)
with pytest.raises(DatasetError, match=re.escape(pattern)):
DataCatalog.from_config(**sane_config)
Expand Down

0 comments on commit 1c95627

Please sign in to comment.