Skip to content

Commit

Permalink
feat(datasets): create custom DeprecationWarning (#356)
Browse files Browse the repository at this point in the history
* feat(datasets): create custom `DeprecationWarning`

Signed-off-by: Deepyaman Datta <[email protected]>

* feat(datasets): use the custom deprecation warning

Signed-off-by: Deepyaman Datta <[email protected]>

* chore(datasets): show Kedro's deprecation warnings

Signed-off-by: Deepyaman Datta <[email protected]>

* fix(datasets): remove unused imports in test files

Signed-off-by: Deepyaman Datta <[email protected]>

---------

Signed-off-by: Deepyaman Datta <[email protected]>
  • Loading branch information
deepyaman authored Oct 2, 2023
1 parent 0192170 commit 5f884e6
Show file tree
Hide file tree
Showing 83 changed files with 263 additions and 83 deletions.
16 changes: 16 additions & 0 deletions kedro-datasets/kedro_datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
"""``kedro_datasets`` is where you can find all of Kedro's data connectors."""

__all__ = ["KedroDeprecationWarning"]
__version__ = "1.7.0"

import sys
import warnings

try:
# Custom `KedroDeprecationWarning` class was added in Kedro 0.18.14.
from kedro import KedroDeprecationWarning
except ImportError:

class KedroDeprecationWarning(DeprecationWarning):
"""Custom class for warnings about deprecated Kedro features."""


if not sys.warnoptions:
warnings.simplefilter("default", KedroDeprecationWarning)
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/api/api_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from requests import Session, sessions
from requests.auth import AuthBase

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractDataset, DatasetError


Expand Down Expand Up @@ -248,7 +249,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from Bio import SeqIO
from kedro.io.core import get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractDataset


Expand Down Expand Up @@ -150,7 +151,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/dask/parquet_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import triad
from kedro.io.core import get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractDataset


Expand Down Expand Up @@ -222,7 +223,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pyspark.sql.types import StructType
from pyspark.sql.utils import AnalysisException, ParseException

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -450,7 +451,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/email/message_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import fsspec
from kedro.io.core import Version, get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError


Expand Down Expand Up @@ -193,7 +194,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/geopandas/geojson_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import geopandas as gpd
from kedro.io.core import Version, get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError


Expand Down Expand Up @@ -164,7 +165,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/json/json_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fsspec
from kedro.io.core import Version, get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError


Expand Down Expand Up @@ -167,7 +168,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/networkx/gml_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import networkx
from kedro.io.core import Version, get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset


Expand Down Expand Up @@ -152,7 +153,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/networkx/graphml_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import networkx
from kedro.io.core import Version, get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset


Expand Down Expand Up @@ -150,7 +151,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/networkx/json_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import networkx
from kedro.io.core import Version, get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset


Expand Down Expand Up @@ -157,7 +158,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/csv_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
get_protocol_and_path,
)

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -214,7 +215,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/deltatable_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from deltalake.exceptions import TableNotFoundError
from deltalake.writer import write_deltalake

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractDataset, DatasetError


Expand Down Expand Up @@ -271,7 +272,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/excel_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
get_protocol_and_path,
)

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -282,7 +283,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/feather_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get_protocol_and_path,
)

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -202,7 +203,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/gbq_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
validate_on_forbidden_chars,
)

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractDataset, DatasetError


Expand Down Expand Up @@ -330,7 +331,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/generic_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas as pd
from kedro.io.core import Version, get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError

NON_FILE_SYSTEM_TARGETS = [
Expand Down Expand Up @@ -252,7 +253,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/hdf_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas as pd
from kedro.io.core import Version, get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError

HDFSTORE_DRIVER = "H5FD_CORE"
Expand Down Expand Up @@ -212,7 +213,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/json_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
get_protocol_and_path,
)

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -200,7 +201,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/parquet_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
get_protocol_and_path,
)

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -226,7 +227,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/sql_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sqlalchemy import create_engine, inspect
from sqlalchemy.exc import NoSuchModuleError

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractDataset, DatasetError

__all__ = ["SQLTableDataset", "SQLQueryDataset"]
Expand Down Expand Up @@ -547,7 +548,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pandas/xml_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
get_protocol_and_path,
)

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -184,7 +185,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
3 changes: 2 additions & 1 deletion kedro-datasets/kedro_datasets/pickle/pickle_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import fsspec
from kedro.io.core import Version, get_filepath_str, get_protocol_and_path

from kedro_datasets import KedroDeprecationWarning
from kedro_datasets._io import AbstractVersionedDataset, DatasetError


Expand Down Expand Up @@ -252,7 +253,7 @@ def __getattr__(name):
warnings.warn(
f"{repr(name)} has been renamed to {repr(alias.__name__)}, "
f"and the alias will be removed in Kedro-Datasets 2.0.0",
DeprecationWarning,
KedroDeprecationWarning,
stacklevel=2,
)
return alias
Expand Down
Loading

0 comments on commit 5f884e6

Please sign in to comment.