Skip to content

Commit

Permalink
Improve add_feed_dict docstrings (#4009)
Browse files Browse the repository at this point in the history
* Updated docstring text

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* Updated example

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* Added alias

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* Removed alias

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* Applied suggested changes

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

* Updated docstring based on comments

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>

---------

Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>
  • Loading branch information
ElenaKhaustova authored Jul 17, 2024
1 parent e21e036 commit ea54d60
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions kedro/io/data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,29 +681,39 @@ def add_all(
self.add(name, dataset, replace)

def add_feed_dict(self, feed_dict: dict[str, Any], replace: bool = False) -> None:
"""Adds instances of ``MemoryDataset``, containing the data provided
through feed_dict.
"""Add datasets to the ``DataCatalog`` using the data provided through the `feed_dict`.
`feed_dict` is a dictionary where the keys represent dataset names and the values can either be raw data or
Kedro datasets - instances of classes that inherit from ``AbstractDataset``. If raw data is provided,
it will be automatically wrapped in a ``MemoryDataset`` before being added to the ``DataCatalog``.
Args:
feed_dict: A feed dict with data to be added in memory.
replace: Specifies whether to replace an existing dataset
with the same name is allowed.
feed_dict: A dictionary with data to be added to the ``DataCatalog``. Keys are dataset names and
values can be raw data or instances of classes that inherit from ``AbstractDataset``.
replace: Specifies whether to replace an existing dataset with the same name in the ``DataCatalog``.
Example:
::
>>> from kedro_datasets.pandas import CSVDataset
>>> import pandas as pd
>>>
>>> df = pd.DataFrame({'col1': [1, 2],
>>> 'col2': [4, 5],
>>> 'col3': [5, 6]})
>>> df = pd.DataFrame({"col1": [1, 2],
>>> "col2": [4, 5],
>>> "col3": [5, 6]})
>>>
>>> io = DataCatalog()
>>> io.add_feed_dict({
>>> 'data': df
>>> catalog = DataCatalog()
>>> catalog.add_feed_dict({
>>> "data_df": df
>>> }, replace=True)
>>>
>>> assert io.load("data").equals(df)
>>> assert catalog.load("data_df").equals(df)
>>>
>>> csv_dataset = CSVDataset(filepath="test.csv")
>>> csv_dataset.save(df)
>>> catalog.add_feed_dict({"data_csv_dataset": csv_dataset})
>>>
>>> assert catalog.load("data_csv_dataset").equals(df)
"""
for dataset_name in feed_dict:
if isinstance(feed_dict[dataset_name], AbstractDataset):
Expand Down

0 comments on commit ea54d60

Please sign in to comment.