Skip to content

Commit

Permalink
Fix catalog shallow copy changing class type (#3950)
Browse files Browse the repository at this point in the history
* Catalog shallow copy should use specified class type and not cast to DataCatalog

Signed-off-by: Merel Theisen <[email protected]>
  • Loading branch information
merelcht authored Jun 18, 2024
1 parent b6e585f commit ff133a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 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.
* 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
2 changes: 1 addition & 1 deletion kedro/io/data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def shallow_copy(
dataset_patterns = self._sort_patterns(unsorted_dataset_patterns)
else:
dataset_patterns = self._dataset_patterns
return DataCatalog(
return self.__class__(
datasets=self._datasets,
dataset_patterns=dataset_patterns,
load_versions=self._load_versions,
Expand Down
12 changes: 11 additions & 1 deletion tests/io/test_data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,21 @@ def test_confirm(self, mocker, caplog):
],
)
def test_bad_confirm(self, data_catalog, dataset_name, error_pattern):
"""Test confirming a non existent dataset or one that
"""Test confirming a non-existent dataset or one that
does not have `confirm` method"""
with pytest.raises(DatasetError, match=re.escape(error_pattern)):
data_catalog.confirm(dataset_name)

def test_shallow_copy_returns_correct_class_type(
self,
):
class MyDataCatalog(DataCatalog):
pass

data_catalog = MyDataCatalog()
copy = data_catalog.shallow_copy()
assert isinstance(copy, MyDataCatalog)


class TestDataCatalogFromConfig:
def test_from_sane_config(self, data_catalog_from_config, dummy_dataframe):
Expand Down

0 comments on commit ff133a5

Please sign in to comment.