Skip to content

Commit

Permalink
Bug fix for parse dataest definition (#3400)
Browse files Browse the repository at this point in the history
* add tests to test definitio explicitly

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

* fix tests

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

* update docstring

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

---------

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
  • Loading branch information
noklam authored Dec 11, 2023
1 parent 292df1d commit 0b45b7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kedro/io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def parse_dataset_definition(
Args:
config: Data set config dictionary. It *must* contain the `type` key
with fully qualified class name.
with fully qualified class name or the class object.
load_version: Version string to be used for ``load`` operation if
the data set is versioned. Has no effect on the data set
if versioning was not enabled.
Expand All @@ -378,6 +378,7 @@ def parse_dataset_definition(
raise DatasetError("'type' is missing from dataset catalog configuration")

dataset_type = config.pop("type")
class_obj = None
if isinstance(dataset_type, str):
if len(dataset_type.strip(".")) != len(dataset_type):
raise DatasetError(
Expand All @@ -394,6 +395,9 @@ def parse_dataset_definition(
else:
raise DatasetError(f"Class '{dataset_type}' not found, is this a typo?")

if not class_obj:
class_obj = dataset_type

if not issubclass(class_obj, AbstractDataset):
raise DatasetError(
f"Dataset type '{class_obj.__module__}.{class_obj.__qualname__}' "
Expand Down
10 changes: 10 additions & 0 deletions tests/io/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
parse_dataset_definition,
validate_on_forbidden_chars,
)
from kedro.io.lambda_dataset import LambdaDataset

# List sourced from https://docs.python.org/3/library/stdtypes.html#truth-value-testing.
# Excludes None, as None values are not shown in the str representation.
Expand Down Expand Up @@ -292,6 +293,15 @@ def side_effect_function(value):
with pytest.raises(DatasetError, match=pattern):
parse_dataset_definition({"type": dataset_name})

def test_parse_dataset_definition(self):
config = {"type": "LambdaDataset"}
dataset, _ = parse_dataset_definition(config)
assert dataset is LambdaDataset

def test_test_parse_dataset_definition_with_python_class_type(self):
config = {"type": MyDataset}
parse_dataset_definition(config)


class TestAbstractVersionedDataset:
def test_version_str_repr(self, load_version, save_version):
Expand Down

0 comments on commit 0b45b7f

Please sign in to comment.