Repository: kedro-org/kedro
File: kedro/io/kedro_data_catalog.py (Python)

Code before:
        return self.get_dataset(ds_name)

    def __setitem__(self, key: str, value: Any) -> None:
        """Add dataset to the ``KedroDataCatalog`` using the given key as a datsets name
        and the provided data as the value.

        The value can either be raw data or a Kedro dataset (i.e., an instance of a class
        inheriting from ``AbstractDataset``). If raw data is provided, it will be automatically
        wrapped in a ``MemoryDataset`` before being added to the catalog.

        Args:
            key: Name of the dataset.
            value: Raw data or an instance of a class inheriting from ``AbstractDataset``.

        Example:
        ::

            >>> from kedro_datasets.pandas import CSVDataset
            >>> import pandas as pd
            >>>
            >>> df = pd.DataFrame({"col1": [1, 2],
            >>>                    "col2": [4, 5],
            >>>                    "col3": [5, 6]})
            >>>
            >>> catalog = KedroDataCatalog()
            >>> catalog["data_df"] = df  # Add raw data as a dataset
            >>>
            >>> assert catalog.load("data_df").equals(df)
            >>>
            >>> csv_dataset = CSVDataset(filepath="test.csv")
            >>> csv_dataset.save(df)
            >>> catalog["data_csv_dataset"] = csv_dataset  # Add a dataset instance
            >>>
            >>> assert catalog.load("data_csv_dataset").equals(df)
        """
        if key in self._datasets:
            self._logger.warning("Replacing dataset '%s'", key)
        if isinstance(value, AbstractDataset):
            self._datasets[key] = value
        else:
            self._logger.info(f"Adding input data as a MemoryDataset - {key}")
            self._datasets[key] = MemoryDataset(data=value)  # type: ignore[abstract]

    def __len__(self) -> int:
        return len(self.keys())

    def get(
        self, key: str, default: AbstractDataset | None = None
    ) -> AbstractDataset | None:
        """Get a dataset by name from an internal collection of datasets.


Review comment (suggestion):
```suggestion
            >>> catalog["data_df"] = df  # Add raw data as a MemoryDataset
```

Code after:
        return self.get_dataset(ds_name)

    def __setitem__(self, key: str, value: Any) -> None:
        """Add dataset to the ``KedroDataCatalog`` using the given key as a datsets name
        and the provided data as the value.

        The value can either be raw data or a Kedro dataset (i.e., an instance of a class
        inheriting from ``AbstractDataset``). If raw data is provided, it will be automatically
        wrapped in a ``MemoryDataset`` before being added to the catalog.

        Args:
            key: Name of the dataset.
            value: Raw data or an instance of a class inheriting from ``AbstractDataset``.

        Example:
        ::

            >>> from kedro_datasets.pandas import CSVDataset
            >>> import pandas as pd
            >>>
            >>> df = pd.DataFrame({"col1": [1, 2],
            >>>                    "col2": [4, 5],
            >>>                    "col3": [5, 6]})
            >>>
            >>> catalog = KedroDataCatalog()
            >>> catalog["data_df"] = df  # Add raw data as a MemoryDataset
            >>>
            >>> assert catalog.load("data_df").equals(df)
            >>>
            >>> csv_dataset = CSVDataset(filepath="test.csv")
            >>> csv_dataset.save(df)
            >>> catalog["data_csv_dataset"] = csv_dataset  # Add a dataset instance
            >>>
            >>> assert catalog.load("data_csv_dataset").equals(df)
        """
        if key in self._datasets:
            self._logger.warning("Replacing dataset '%s'", key)
        if isinstance(value, AbstractDataset):
            self._datasets[key] = value
        else:
            self._logger.info(f"Adding input data as a MemoryDataset - {key}")
            self._datasets[key] = MemoryDataset(data=value)  # type: ignore[abstract]

    def __len__(self) -> int:
        return len(self.keys())

    def get(
        self, key: str, default: AbstractDataset | None = None
    ) -> AbstractDataset | None:
        """Get a dataset by name from an internal collection of datasets.