From a1e8d159cb1b5a36c06517612e10ce052f24ee4c Mon Sep 17 00:00:00 2001 From: Deepyaman Datta Date: Sat, 22 Jul 2023 11:39:06 -0500 Subject: [PATCH] perf(datasets): lazily load datasets in init files Signed-off-by: Deepyaman Datta --- .../kedro_datasets/pandas/__init__.py | 56 ++++++------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/kedro-datasets/kedro_datasets/pandas/__init__.py b/kedro-datasets/kedro_datasets/pandas/__init__.py index 2ac29379a..ae63b076f 100644 --- a/kedro-datasets/kedro_datasets/pandas/__init__.py +++ b/kedro-datasets/kedro_datasets/pandas/__init__.py @@ -1,42 +1,20 @@ """``AbstractDataSet`` implementations that produce pandas DataFrames.""" -__all__ = [ - "CSVDataSet", - "DeltaTableDataSet", - "ExcelDataSet", - "FeatherDataSet", - "GBQTableDataSet", - "GBQQueryDataSet", - "HDFDataSet", - "JSONDataSet", - "ParquetDataSet", - "SQLQueryDataSet", - "SQLTableDataSet", - "XMLDataSet", - "GenericDataSet", -] +import lazy_loader as lazy -from contextlib import suppress - -with suppress(ImportError): - from .csv_dataset import CSVDataSet -with suppress(ImportError): - from .deltatable_dataset import DeltaTableDataSet -with suppress(ImportError): - from .excel_dataset import ExcelDataSet -with suppress(ImportError): - from .feather_dataset import FeatherDataSet -with suppress(ImportError): - from .gbq_dataset import GBQQueryDataSet, GBQTableDataSet -with suppress(ImportError): - from .hdf_dataset import HDFDataSet -with suppress(ImportError): - from .json_dataset import JSONDataSet -with suppress(ImportError): - from .parquet_dataset import ParquetDataSet -with suppress(ImportError): - from .sql_dataset import SQLQueryDataSet, SQLTableDataSet -with suppress(ImportError): - from .xml_dataset import XMLDataSet -with suppress(ImportError): - from .generic_dataset import GenericDataSet +__getattr__, __dir__, __all__ = lazy.attach( + __name__, + submod_attrs={ + "csv_dataset": ["CSVDataSet"], + "deltatable_dataset": ["DeltaTableDataSet"], + "excel_dataset": ["ExcelDataSet"], + "feather_dataset": ["FeatherDataSet"], + "gbq_dataset": ["GBQQueryDataSet", "GBQTableDataSet"], + "generic_dataset": ["GenericDataSet"], + "hdf_dataset": ["HDFDataSet"], + "json_dataset": ["JSONDataSet"], + "parquet_dataset": ["ParquetDataSet"], + "sql_dataset": ["SQLQueryDataSet", "SQLTableDataSet"], + "xml_dataset": ["XMLDataSet"], + }, +)