From 1903973bbbc9ab61628cf813b560630d422a6cf9 Mon Sep 17 00:00:00 2001 From: Ankita Katiyar Date: Thu, 13 Jun 2024 16:08:48 +0100 Subject: [PATCH 1/4] Update error message when kedro-datasets is not installed Signed-off-by: Ankita Katiyar --- kedro/io/core.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kedro/io/core.py b/kedro/io/core.py index ec1b25bfea..0800fdd9bf 100644 --- a/kedro/io/core.py +++ b/kedro/io/core.py @@ -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: @@ -406,7 +406,21 @@ 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 = ( + "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`." + ) + raise DatasetError( + f"Class '{dataset_type}' not found, is this a typo?" f"\n{hint}" + ) if not class_obj: class_obj = dataset_type From 1c6e6d2115b8a4edf54cd826f36c14e64d825072 Mon Sep 17 00:00:00 2001 From: Ankita Katiyar Date: Fri, 14 Jun 2024 11:49:20 +0100 Subject: [PATCH 2/4] Release notes, update error hint Signed-off-by: Ankita Katiyar --- RELEASE.md | 1 + kedro/io/core.py | 4 +++- tests/io/test_data_catalog.py | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 21925f4395..6c029975e2 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -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. ## Breaking changes to the API diff --git a/kedro/io/core.py b/kedro/io/core.py index 0800fdd9bf..165c68c3e1 100644 --- a/kedro/io/core.py +++ b/kedro/io/core.py @@ -416,7 +416,9 @@ def parse_dataset_definition( 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`." + "You can do so by running `pip install kedro-datasets` or " + "`pip install kedro-datasets[]` 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}" diff --git a/tests/io/test_data_catalog.py b/tests/io/test_data_catalog.py index 4a4caff7c6..312c3622d9 100644 --- a/tests/io/test_data_catalog.py +++ b/tests/io/test_data_catalog.py @@ -493,7 +493,20 @@ 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) + + 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) From 28daf592de2aefb6f709feaeb29e8d8ce6e9969f Mon Sep 17 00:00:00 2001 From: Ankita Katiyar Date: Fri, 14 Jun 2024 12:59:25 +0100 Subject: [PATCH 3/4] Skip test for python 3.8 Signed-off-by: Ankita Katiyar --- tests/io/test_data_catalog.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/io/test_data_catalog.py b/tests/io/test_data_catalog.py index 312c3622d9..72bb15968a 100644 --- a/tests/io/test_data_catalog.py +++ b/tests/io/test_data_catalog.py @@ -1,5 +1,6 @@ import logging import re +import sys from copy import deepcopy from datetime import datetime, timezone from pathlib import Path @@ -498,6 +499,10 @@ def test_config_missing_class(self, sane_config): 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" From 19709c5f63474bc806b2c4523f21a2d5591395fc Mon Sep 17 00:00:00 2001 From: Ankita Katiyar Date: Fri, 14 Jun 2024 14:33:42 +0100 Subject: [PATCH 4/4] Ignore test coverage Signed-off-by: Ankita Katiyar --- kedro/io/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/io/core.py b/kedro/io/core.py index 165c68c3e1..ff388a50ed 100644 --- a/kedro/io/core.py +++ b/kedro/io/core.py @@ -408,7 +408,7 @@ def parse_dataset_definition( else: hint = "" if "DataSet" in dataset_type: - hint = ( + 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`." )