From 7537eaecab5b9875a73b53b8f838a3c417cc2f2c Mon Sep 17 00:00:00 2001 From: Felix Scherz Date: Tue, 24 Sep 2024 17:55:55 +0200 Subject: [PATCH] fix: implement `_exists` for `SharedMemoryDataset` (#4121) * fix: implement `_exists` for `SharedMemoryDataset` Signed-off-by: Felix Scherz * docs: updated RELEASE.md Signed-off-by: Felix Scherz * fix: ignore mypy warning on exists return type Signed-off-by: Felix Scherz --------- Signed-off-by: Felix Scherz Signed-off-by: Ankita Katiyar <110245118+ankatiyar@users.noreply.github.com> Co-authored-by: Ankita Katiyar <110245118+ankatiyar@users.noreply.github.com> --- RELEASE.md | 2 ++ kedro/io/shared_memory_dataset.py | 5 +++++ tests/io/test_shared_memory_dataset.py | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/RELEASE.md b/RELEASE.md index da18b8d172..61560acf87 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -14,6 +14,7 @@ * Enhanced `OmegaConfigLoader` configuration validation to detect duplicate keys at all parameter levels, ensuring comprehensive nested key checking. ## Bug fixes and other changes * Fixed bug where using dataset factories breaks with `ThreadRunner`. +* Fixed a bug where `SharedMemoryDataset.exists` would not call the underlying `MemoryDataset`. * Fixed template projects example tests. * Made credentials loading consistent between `KedroContext._get_catalog()` and `resolve_patterns` so that both us e `_get_config_credentials()` @@ -30,6 +31,7 @@ e `_get_config_credentials()` * [ethanknights](https://github.com/ethanknights) * [Manezki](https://github.com/Manezki) * [MigQ2](https://github.com/MigQ2) +* [Felix Scherz](https://github.com/felixscherz) # Release 0.19.8 diff --git a/kedro/io/shared_memory_dataset.py b/kedro/io/shared_memory_dataset.py index a7e28d0256..139180b578 100644 --- a/kedro/io/shared_memory_dataset.py +++ b/kedro/io/shared_memory_dataset.py @@ -57,3 +57,8 @@ def save(self, data: Any) -> None: def _describe(self) -> dict[str, Any]: """SharedMemoryDataset doesn't have any constructor argument to return.""" return {} + + def _exists(self) -> bool: + if not self.shared_memory_dataset: + return False + return self.shared_memory_dataset.exists() # type: ignore[no-any-return] diff --git a/tests/io/test_shared_memory_dataset.py b/tests/io/test_shared_memory_dataset.py index d135b3aadd..a4b3526aa4 100644 --- a/tests/io/test_shared_memory_dataset.py +++ b/tests/io/test_shared_memory_dataset.py @@ -79,3 +79,9 @@ def test_saving_none(self, shared_memory_dataset): def test_str_representation(self, shared_memory_dataset): """Test string representation of the dataset""" assert "MemoryDataset" in str(shared_memory_dataset) + + def test_exists(self, shared_memory_dataset, input_data): + """Check that exists returns the expected values""" + assert not shared_memory_dataset.exists() + shared_memory_dataset.save(input_data) + assert shared_memory_dataset.exists()