DataCatalog
kedro.io.DataCatalog ¶
DataCatalog(datasets=None, config_resolver=None, load_versions=None, save_version=None)
Bases: CatalogProtocol
A centralized registry for managing datasets in a Kedro project.
The DataCatalog
provides a unified interface for loading and saving datasets,
enabling seamless interaction with various data sources and formats. It supports
features such as lazy loading, versioning, and dynamic dataset creation using dataset
factory patterns.
This class is the core component of Kedro's data management system, allowing datasets to be defined, accessed, and manipulated in a consistent and reusable way.
Attributes:
-
default_runtime_patterns
(ClassVar
) –A dictionary defining the default runtime pattern for datasets of type
kedro.io.MemoryDataset
. -
_datasets
(dict[str, AbstractDataset]
) –A dictionary of fully initialized datasets.
-
_lazy_datasets
(dict[str, _LazyDataset]
) –A dictionary of
_LazyDataset
instances for deferred initialization. -
_load_versions
(dict[str, _LazyDataset]
) –A mapping of dataset names to specific versions to load.
-
_save_version
(dict[str, _LazyDataset]
) –The global version string for saving datasets.
-
_config_resolver
–Resolves dataset factory patterns and configurations.
Example: ::
>>> from kedro.io import DataCatalog, MemoryDataset
>>>
>>> # Define datasets
>>> datasets = {
... "cars": MemoryDataset(data={"type": "car", "capacity": 5}),
... "planes": MemoryDataset(data={"type": "jet", "capacity": 200}),
... }
>>>
>>> # Initialize the catalog
>>> catalog = DataCatalog(datasets=datasets)
>>>
>>> # Load data
>>> cars_data = catalog.load("cars")
>>> print(cars_data)
>>>
>>> # Save data
>>> catalog.save("planes", {"type": "propeller", "capacity": 100})
>>> planes_data = catalog.load("planes")
>>> print(planes_data)
This catalog combines datasets passed directly via the datasets
argument and dynamic datasets
resolved from config (e.g., from YAML).
If a dataset name is present in both datasets
and the resolved config, the dataset from datasets
takes precedence. A warning is logged, and the config-defined dataset is skipped and removed from
the internal config.
Parameters:
-
datasets
(dict[str, AbstractDataset] | None
, default:None
) –A dictionary of dataset names and dataset instances.
-
config_resolver
(CatalogConfigResolver | None
, default:None
) –An instance of CatalogConfigResolver to resolve dataset factory patterns and configurations.
-
load_versions
(dict[str, str] | None
, default:None
) –A mapping between dataset names and versions to load. Has no effect on datasets without enabled versioning.
-
save_version
(str | None
, default:None
) –Version string to be used for
save
operations by all datasets with enabled versioning. It must: a) be a case-insensitive string that conforms with operating system filename limitations, b) always return the latest version when sorted in lexicographical order.
Example: ::
>>> from kedro.io import DataCatalog, MemoryDataset
>>> from kedro_datasets.pandas import CSVDataset
>>> # Define datasets
>>> datasets = {
... "cars": CSVDataset(filepath="cars.csv"),
... "planes": MemoryDataset(data={"type": "jet", "capacity": 200}),
... }
>>> # Initialize the catalog
>>> catalog = DataCatalog(
... datasets=datasets,
... load_versions={"cars": "2023-01-01T00.00.00"},
... save_version="2023-01-02T00.00.00",
... )
>>> print(catalog)
Source code in kedro/io/data_catalog.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
_config_resolver
instance-attribute
¶
_config_resolver = config_resolver or CatalogConfigResolver(default_runtime_patterns=default_runtime_patterns)
config_resolver
property
¶
config_resolver
Get the CatalogConfigResolver
instance associated with this DataCatalog
.
The CatalogConfigResolver
is responsible for resolving dataset factory patterns
and configurations dynamically.
Returns:
-
CatalogConfigResolver
–The configuration resolver for the catalog.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> resolver = catalog.config_resolver
>>> print(resolver)
default_runtime_patterns
class-attribute
instance-attribute
¶
default_runtime_patterns = {'{default}': {'type': 'kedro.io.MemoryDataset'}}
__contains__ ¶
__contains__(dataset_name)
Check if a dataset is registered in the catalog or matches a dataset/user catch all pattern
Parameters:
-
dataset_name
(str
) –The name of the dataset to check.
Returns:
-
bool
–True if the dataset is registered or matches a pattern, False otherwise.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> "example" in catalog
# True
>>> "nonexistent" in catalog
# False
Source code in kedro/io/data_catalog.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
__eq__ ¶
__eq__(other)
Compare two catalogs based on materialized datasets, lazy datasets and all dataset factory patterns.
Parameters:
-
other
–Another
DataCatalog
instance to compare.
Returns:
-
bool
–True if the catalogs are equivalent, False otherwise.
Example: ::
>>> catalog1 = DataCatalog(datasets={"example": MemoryDataset()})
>>> catalog2 = DataCatalog(datasets={"example": MemoryDataset()})
>>> catalog1 == catalog2
# False
Source code in kedro/io/data_catalog.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
__getitem__ ¶
__getitem__(ds_name)
Get a dataset by name from the catalog.
If a dataset is not materialized but matches dataset_pattern or user_catch_all_pattern by default or runtime_patterns if fallback_to_runtime_pattern is enabled it is instantiated and added to the catalog first, then returned.
Parameters:
-
ds_name
(str
) –The name of the dataset.
Returns:
-
AbstractDataset | None
–The dataset instance if found, otherwise None.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> dataset = catalog["example"]
>>> print(dataset)
# MemoryDataset()
Source code in kedro/io/data_catalog.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
|
__iter__ ¶
__iter__()
Iterate over all dataset names in the catalog, including both materialized and lazy datasets.
Yields:
-
str
–Dataset names.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> for dataset_name in catalog:
... print(dataset_name)
# example
Source code in kedro/io/data_catalog.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
__len__ ¶
__len__()
Get the number of datasets registered in the catalog, including both materialized and lazy datasets.
Returns:
-
int
–The number of datasets.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> len(catalog)
# 1
Source code in kedro/io/data_catalog.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
__repr__ ¶
__repr__()
Return a string representation of the DataCatalog
.
The representation includes both lazy and fully initialized datasets in the catalog.
Returns:
-
str
–A string representation of the catalog.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> print(repr(catalog))
# "example: kedro.io.memory_dataset.MemoryDataset()"
Source code in kedro/io/data_catalog.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
__setitem__ ¶
__setitem__(key, value)
Registers a dataset or raw data into the catalog using the specified name.
If the name already exists, the dataset will be replaced and relevant internal mappings (lazy datasets, config, versions) will be cleared to avoid conflicts.
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.
Parameters:
-
key
(str
) –Name of the dataset.
-
value
(Any
) –Either an instance of
AbstractDataset
,_LazyDataset
, or raw data (e.g., DataFrame, list). If raw data is provided, it is automatically wrapped as aMemoryDataset
.
Example: ::
>>> from kedro_datasets.pandas import CSVDataset
>>> import pandas as pd
>>>
>>> df = pd.DataFrame({"col1": [1, 2],
>>> "col2": [4, 5],
>>> "col3": [5, 6]})
>>>
>>> catalog = DataCatalog()
>>> 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)
Source code in kedro/io/data_catalog.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
|
_add_from_config ¶
_add_from_config(ds_name, ds_config)
Create a _LazyDataset
instance from the provided configuration and add it to the catalog.
This method validates the dataset configuration, creates a _LazyDataset
instance,
and registers it in the catalog. The _LazyDataset
is a placeholder for a dataset
that will be materialized only when accessed.
Parameters:
-
ds_name
(str
) –The name of the dataset to be added.
-
ds_config
(dict[str, Any]
) –The configuration dictionary for the dataset.
Raises:
-
DatasetError
–If the provided dataset configuration is invalid (e.g., missing required keys like "type" or improperly formatted).
Example: ::
>>> catalog = DataCatalog()
>>> dataset_config = {"type": "pandas.CSVDataset", "filepath": "example.csv"}
>>> catalog._add_from_config("example_dataset", dataset_config)
>>> "example_dataset" in catalog
# True
Source code in kedro/io/data_catalog.py
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
|
_ipython_key_completions_ ¶
_ipython_key_completions_()
Source code in kedro/io/data_catalog.py
596 597 |
|
_validate_dataset_config
staticmethod
¶
_validate_dataset_config(ds_name, ds_config)
Validate the configuration of a dataset in the catalog.
This method ensures that the dataset configuration is a dictionary and contains
the required "type" key. If the configuration is invalid, it raises a DatasetError
with a helpful error message.
Parameters:
-
ds_name
(str
) –The name of the dataset being validated.
-
ds_config
(Any
) –The configuration of the dataset to validate.
Raises:
-
DatasetError
–If the dataset configuration is not a dictionary or if the "type" key is missing from the configuration.
Example: ::
>>> config = {
... "example_dataset": {
... "type": "pandas.CSVDataset",
... "filepath": "example.csv",
... }
... }
>>> DataCatalog._validate_dataset_config(
... "example_dataset", config["example_dataset"]
... )
# No error raised
>>> invalid_config = {"example_dataset": {"filepath": "example.csv"}}
>>> DataCatalog._validate_dataset_config(
... "example_dataset", invalid_config["example_dataset"]
... )
# Raises DatasetError: "'type' is missing from dataset catalog configuration."
Source code in kedro/io/data_catalog.py
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 |
|
_validate_versions
staticmethod
¶
_validate_versions(datasets, load_versions, save_version)
Validates and synchronises dataset versions for loading and saving.
Ensures consistency of dataset versions across a catalog, particularly for versioned datasets. It updates load versions and validates that all save versions are consistent.
Parameters:
-
datasets
(dict[str, AbstractDataset] | None
) –A dictionary mapping dataset names to their instances. if None, no validation occurs.
-
load_versions
(dict[str, str]
) –A mapping between dataset names and versions to load.
-
save_version
(str | None
) –Version string to be used for
save
operations by all datasets with versioning enabled.
Returns:
-
tuple[dict[str, str], str | None]
–Updated
load_versions
with load versions specified in thedatasets
and resolvedsave_version
.
Raises:
-
VersionAlreadyExistsError
–If a dataset's save version conflicts with the catalog's save version.
Source code in kedro/io/data_catalog.py
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 |
|
confirm ¶
confirm(ds_name)
Confirm a dataset by its name.
Args:
ds_name: Name of the dataset.
Raises:
DatasetNotFoundError: When a dataset with the given name
has not yet been registered
DatasetError: When the dataset does not have confirm
method.
Source code in kedro/io/data_catalog.py
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
|
exists ¶
exists(ds_name)
Checks whether registered dataset exists by calling its exists()
method. Raises a warning and returns False if exists()
is not
implemented.
Parameters:
-
ds_name
(str
) –A dataset to be checked.
Returns:
-
bool
–Whether the dataset and its output exist.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset(data=[1, 2, 3])})
>>> catalog.exists("example")
True
Source code in kedro/io/data_catalog.py
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 |
|
filter ¶
filter(name_regex=None, type_regex=None, by_type=None)
Filter dataset names registered in the catalog based on name and/or type.
This method allows filtering datasets by their names and/or types. Regular expressions
should be precompiled before passing them to name_regex
or type_regex
, but plain
strings are also supported.
Parameters:
-
name_regex
(Pattern[str] | str | None
, default:None
) –Optional compiled regex pattern or string to filter dataset names.
-
type_regex
(Pattern[str] | str | None
, default:None
) –Optional compiled regex pattern or string to filter dataset types. The provided regex is matched against the full dataset type path, for example:
kedro_datasets.pandas.parquet_dataset.ParquetDataset
. -
by_type
(type | list[type] | None
, default:None
) –Optional dataset type(s) to filter by. This performs an instance type check rather than a regex match. It can be a single dataset type or a list of types.
Returns:
-
List[str]
–A list of dataset names that match the filtering criteria.
Example: ::
>>> import re
>>> catalog = DataCatalog()
>>> # get datasets where the substring 'raw' is present
>>> raw_data = catalog.filter(name_regex='raw')
>>> # get datasets where names start with 'model_' (precompiled regex)
>>> model_datasets = catalog.filter(name_regex=re.compile('^model_'))
>>> # get datasets of a specific type using type_regex
>>> csv_datasets = catalog.filter(type_regex='pandas.excel_dataset.ExcelDataset')
>>> # get datasets where names contain 'train' and type matches 'CSV' in the path
>>> catalog.filter(name_regex="train", type_regex="CSV")
>>> # get datasets where names include 'data' and are of a specific type
>>> from kedro_datasets.pandas import SQLQueryDataset
>>> catalog.filter(name_regex="data", by_type=SQLQueryDataset)
>>> # get datasets where names include 'data' and are of multiple specific types
>>> from kedro.io import MemoryDataset
>>> catalog.filter(name_regex="data", by_type=[MemoryDataset, SQLQueryDataset])
Source code in kedro/io/data_catalog.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 |
|
from_config
classmethod
¶
from_config(catalog, credentials=None, load_versions=None, save_version=None)
Create a DataCatalog
instance from configuration. This is a
factory method used to provide developers with a way to instantiate
DataCatalog
with configuration parsed from configuration files.
Parameters:
-
catalog
(dict[str, dict[str, Any]] | None
) –A dictionary whose keys are the dataset names and the values are dictionaries with the constructor arguments for classes implementing
AbstractDataset
. The dataset class to be loaded is specified with the keytype
and their fully qualified class name. Allkedro.io
dataset can be specified by their class name only, i.e. their module name can be omitted. -
credentials
(dict[str, dict[str, Any]] | None
, default:None
) –A dictionary containing credentials for different datasets. Use the
credentials
key in aAbstractDataset
to refer to the appropriate credentials as shown in the example below. -
load_versions
(dict[str, str] | None
, default:None
) –A mapping between dataset names and versions to load. Has no effect on datasets without enabled versioning.
-
save_version
(str | None
, default:None
) –Version string to be used for
save
operations by all datasets with enabled versioning. It must: a) be a case-insensitive string that conforms with operating system filename limitations, b) always return the latest version when sorted in lexicographical order.
Returns:
-
DataCatalog
–An instantiated
DataCatalog
containing all specified -
DataCatalog
–datasets, created and ready to use.
Raises:
-
DatasetNotFoundError
–When
load_versions
refers to a dataset that doesn't exist in the catalog.
Example: ::
>>> config = {
>>> "cars": {
>>> "type": "pandas.CSVDataset",
>>> "filepath": "cars.csv",
>>> "save_args": {
>>> "index": False
>>> }
>>> },
>>> "boats": {
>>> "type": "pandas.CSVDataset",
>>> "filepath": "s3://aws-bucket-name/boats.csv",
>>> "credentials": "boats_credentials",
>>> "save_args": {
>>> "index": False
>>> }
>>> }
>>> }
>>>
>>> credentials = {
>>> "boats_credentials": {
>>> "client_kwargs": {
>>> "aws_access_key_id": "<your key id>",
>>> "aws_secret_access_key": "<your secret>"
>>> }
>>> }
>>> }
>>>
>>> catalog = DataCatalog.from_config(config, credentials)
>>>
>>> df = catalog.load("cars")
>>> catalog.save("boats", df)
Source code in kedro/io/data_catalog.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
|
get ¶
get(key, fallback_to_runtime_pattern=False, version=None)
Get a dataset by name from an internal collection of datasets.
If a dataset is not materialized but matches dataset_pattern or user_catch_all_pattern by default or runtime_patterns if fallback_to_runtime_pattern is enabled it is instantiated and added to the catalog first, then returned.
Parameters:
-
key
(str
) –A dataset name.
-
fallback_to_runtime_pattern
(bool
, default:False
) –Whether to use runtime_pattern to resolve dataset.
-
version
(Version | None
, default:None
) –Optional argument to get a specific version of the dataset.
Returns:
-
AbstractDataset | None
–The dataset instance if found, otherwise None.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> dataset = catalog.get("example")
>>> print(dataset)
# MemoryDataset()
>>>
>>> missing = catalog.get("nonexistent")
>>> print(missing)
# None
Source code in kedro/io/data_catalog.py
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
|
get_type ¶
get_type(ds_name)
Access dataset type without adding resolved dataset to the catalog.
Parameters:
-
ds_name
(str
) –The name of the dataset whose type is to be retrieved.
Returns:
-
str | None
–The fully qualified type of the dataset (e.g.,
kedro.io.memory_dataset.MemoryDataset
) -
str | None
–or None if dataset does not match dataset_patterns or user_catch_all_pattern.
Example: ::
>>> from kedro.io import DataCatalog, MemoryDataset
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> dataset_type = catalog.get_type("example")
>>> print(dataset_type)
# kedro.io.memory_dataset.MemoryDataset
>>>
>>> missing_type = catalog.get_type("nonexistent")
>>> print(missing_type)
# None
Source code in kedro/io/data_catalog.py
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 |
|
items ¶
items()
Retrieve all dataset names and their corresponding dataset instances.
This method returns a list of tuples, where each tuple contains a dataset name and its corresponding dataset instance.
Returns:
-
List[tuple[str, AbstractDataset]]
–A list of tuples containing dataset names and their corresponding dataset instances.
Example: ::
>>> from kedro.io import DataCatalog, MemoryDataset
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> dataset_items = catalog.items()
>>> print(dataset_items)
# [('example', kedro.io.memory_dataset.MemoryDataset())]
Source code in kedro/io/data_catalog.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|
keys ¶
keys()
List all dataset names registered in the catalog, including both materialized and lazy datasets.
Returns:
-
List[str]
–A list of all dataset names.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> catalog.keys()
# ['example']
Source code in kedro/io/data_catalog.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
load ¶
load(ds_name, version=None)
Loads a registered dataset.
Parameters:
-
ds_name
(str
) –The name of the dataset to be loaded.
-
version
(str | None
, default:None
) –Optional argument for concrete data version to be loaded. Works only with versioned datasets.
Returns:
-
Any
–The loaded data as configured.
Raises:
-
DatasetNotFoundError
–When a dataset with the given name has not yet been registered.
Example: ::
>>> from kedro.io import DataCatalog
>>> from kedro_datasets.pandas import CSVDataset
>>>
>>> cars = CSVDataset(filepath="cars.csv",
>>> load_args=None,
>>> save_args={"index": False})
>>> catalog = DataCatalog(datasets={'cars': cars})
>>>
>>> df = catalog.load("cars")
Source code in kedro/io/data_catalog.py
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 |
|
release ¶
release(ds_name)
Release any cached data associated with a dataset Args: ds_name: A dataset to be checked. Raises: DatasetNotFoundError: When a dataset with the given name has not yet been registered.
Example: ::
>>> catalog = DataCatalog(datasets={"example": MemoryDataset(data=[1, 2, 3])})
>>> catalog.release("example")
Source code in kedro/io/data_catalog.py
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 |
|
save ¶
save(ds_name, data)
Save data to a registered dataset.
Parameters:
-
ds_name
(str
) –The name of the dataset to be saved.
-
data
(Any
) –A data object to be saved as configured in the registered dataset.
Raises:
-
DatasetNotFoundError
–When a dataset with the given name has not yet been registered.
Example: ::
>>> import pandas as pd
>>>
>>> from kedro.io import DataCatalog
>>> from kedro_datasets.pandas import CSVDataset
>>>
>>> cars = CSVDataset(filepath="cars.csv",
>>> load_args=None,
>>> save_args={"index": False})
>>> catalog = DataCatalog(datasets={'cars': cars})
>>>
>>> df = pd.DataFrame({'col1': [1, 2],
>>> 'col2': [4, 5],
>>> 'col3': [5, 6]})
>>> catalog.save("cars", df)
Source code in kedro/io/data_catalog.py
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
|
to_config ¶
to_config()
Converts the DataCatalog
instance into a configuration format suitable for
serialization. This includes datasets, credentials, and versioning information.
This method is only applicable to catalogs that contain datasets initialized with static, primitive
parameters. For example, it will work fine if one passes credentials as dictionary to
GBQQueryDataset
but not as google.auth.credentials.Credentials
object. See
https://github.com/kedro-org/kedro-plugins/issues/950 for the details.
Returns:
-
A tuple containing
–catalog: A dictionary mapping dataset names to their unresolved configurations, excluding in-memory datasets.
credentials: A dictionary of unresolved credentials extracted from dataset configurations.
load_versions: A dictionary mapping dataset names to specific versions to be loaded, or
None
if no version is set.save_version: A global version identifier for saving datasets, or
None
if not specified.
Example: ::
>>> from kedro.io import DataCatalog
>>> from kedro_datasets.pandas import CSVDataset
>>>
>>> cars = CSVDataset(
>>> filepath="cars.csv",
>>> load_args=None,
>>> save_args={"index": False}
>>> )
>>> catalog = DataCatalog(datasets={'cars': cars})
>>>
>>> config, credentials, load_versions, save_version = catalog.to_config()
>>>
>>> new_catalog = DataCatalog.from_config(config, credentials, load_versions, save_version)
Source code in kedro/io/data_catalog.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
|
values ¶
values()
Retrieve all datasets registered in the catalog.
This method returns a list of all dataset instances currently registered in the catalog, including both materialized and lazy datasets.
Returns:
-
List[AbstractDataset]
–A list of dataset instances.
Example: ::
>>> from kedro.io import DataCatalog, MemoryDataset
>>> catalog = DataCatalog(datasets={"example": MemoryDataset()})
>>> dataset_values = catalog.values()
>>> print(dataset_values)
# [kedro.io.memory_dataset.MemoryDataset()]
Source code in kedro/io/data_catalog.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
|