From 9f843495fc639002f5311714e6a6b3d497478228 Mon Sep 17 00:00:00 2001 From: ElenaKhaustova <157851531+ElenaKhaustova@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:55:38 +0000 Subject: [PATCH] Update lazy dataset representation (#4448) * Updated lazy dataset representation Signed-off-by: Elena Khaustova * Updated unit tests Signed-off-by: Elena Khaustova * Updated tests to reach coverage Signed-off-by: Elena Khaustova * Updated release notes Signed-off-by: Elena Khaustova * Updated release notes Signed-off-by: Elena Khaustova --------- Signed-off-by: Elena Khaustova --- .secrets.baseline | 8 ++++++-- RELEASE.md | 2 ++ kedro/io/kedro_data_catalog.py | 4 +++- tests/io/test_kedro_data_catalog.py | 8 +++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 0250f9a16e..f7681ae77b 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -90,6 +90,10 @@ { "path": "detect_secrets.filters.allowlist.is_line_allowlisted" }, + { + "path": "detect_secrets.filters.common.is_baseline_file", + "filename": ".secrets.baseline" + }, { "path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies", "min_level": 2 @@ -211,9 +215,9 @@ "filename": "tests/io/test_kedro_data_catalog.py", "hashed_secret": "15dd2c9ccec914f1470b4dccb45789844e49cf70", "is_verified": false, - "line_number": 499 + "line_number": 501 } ] }, - "generated_at": "2025-01-27T18:47:13Z" + "generated_at": "2025-01-28T14:51:20Z" } diff --git a/RELEASE.md b/RELEASE.md index 4cf8a52c54..f6b17416ab 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -2,6 +2,8 @@ ## Major features and improvements ## Bug fixes and other changes +* Updated `_LazyDataset` representation when printing `KedroDataCatalog`. + ## Breaking changes to the API ## Documentation changes diff --git a/kedro/io/kedro_data_catalog.py b/kedro/io/kedro_data_catalog.py index 9916116504..4e9c782b14 100644 --- a/kedro/io/kedro_data_catalog.py +++ b/kedro/io/kedro_data_catalog.py @@ -27,6 +27,7 @@ Version, _validate_versions, generate_timestamp, + parse_dataset_definition, ) from kedro.io.memory_dataset import MemoryDataset, _is_memory_dataset from kedro.utils import _format_rich, _has_rich_handler @@ -48,7 +49,8 @@ def __init__( self.save_version = save_version def __repr__(self) -> str: - return f"{self.config.get('type', 'UnknownType')}" + class_type, _ = parse_dataset_definition(self.config) + return f"{class_type.__module__}.{class_type.__qualname__}" def materialize(self) -> AbstractDataset: return AbstractDataset.from_config( diff --git a/tests/io/test_kedro_data_catalog.py b/tests/io/test_kedro_data_catalog.py index c3aeef190e..ae1215fd2c 100644 --- a/tests/io/test_kedro_data_catalog.py +++ b/tests/io/test_kedro_data_catalog.py @@ -266,12 +266,14 @@ def test_init_with_raw_data(self, dummy_dataframe, dataset): assert isinstance(catalog["ds"], CSVDataset) assert isinstance(catalog["df"], MemoryDataset) - def test_repr(self, data_catalog): - assert data_catalog.__repr__() == str(data_catalog) + def test_repr(self, data_catalog_from_config): + assert data_catalog_from_config.__repr__() == str(data_catalog_from_config) def test_repr_no_type_found(self, data_catalog_from_config): del data_catalog_from_config._lazy_datasets["boats"].config["type"] - assert data_catalog_from_config.__repr__() == str(data_catalog_from_config) + pattern = "'type' is missing from dataset catalog configuration" + with pytest.raises(DatasetError, match=re.escape(pattern)): + _ = str(data_catalog_from_config) def test_missing_keys_from_load_versions(self, correct_config): """Test load versions include keys missing in the catalog"""