Skip to content

[WIP] Relaxes matplotlib dependency #1227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ads/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,7 @@ def default(self, obj):
),
):
return int(obj)
elif isinstance(
obj, (np.float_, np.float16, np.float32, np.float64, np.double)
):
elif isinstance(obj, (np.float16, np.float32, np.float64, np.double)):
return float(obj)
elif isinstance(obj, (np.ndarray,)):
return obj.tolist()
Expand Down
29 changes: 15 additions & 14 deletions ads/feature_engineering/feature_type/boolean.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*--

# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
# Copyright (c) 2021, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

"""
Expand All @@ -15,19 +14,21 @@
default_handler(data: pd.Series) -> pd.Series
Processes given data and indicates if the data matches requirements.
"""

import matplotlib.pyplot as plt
import pandas as pd

from ads.common.decorator.runtime_dependency import (
OptionalDependency,
runtime_dependency,
)
from ads.feature_engineering import schema
from ads.feature_engineering.feature_type.base import FeatureType
from ads.feature_engineering.utils import (
SchemeTeal,
_count_unique_missing,
is_boolean,
_set_seaborn_theme,
SchemeTeal,
)
from ads.feature_engineering import schema
from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
is_boolean,
)


Expand All @@ -44,7 +45,7 @@ def default_handler(data: pd.Series, *args, **kwargs) -> pd.Series:
:class:`pandas.Series`
The logical list indicating if the data matches requirements.
"""
return pd.Series((is_boolean(value) for value in data.values))
return pd.Series(is_boolean(value) for value in data.values)


class Boolean(FeatureType):
Expand Down Expand Up @@ -74,7 +75,7 @@ class Boolean(FeatureType):
>>> from ads.feature_engineering.feature_type.boolean import Boolean
>>> import pandas as pd
>>> import numpy as np
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='bool')
>>> s = pd.Series([True, False, True, False, np.nan, None], name='bool')
>>> s.ads.feature_type = ['boolean']
>>> Boolean.validator.is_boolean(s)
0 True
Expand Down Expand Up @@ -106,7 +107,7 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:

Examples
--------
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='bool')
>>> s = pd.Series([True, False, True, False, np.nan, None], name='bool')
>>> s.ads.feature_type = ['boolean']
>>> s.ads.feature_stat()
Metric Value
Expand Down Expand Up @@ -134,7 +135,7 @@ def feature_plot(x: pd.Series) -> plt.Axes:

Examples
--------
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='bool')
>>> s = pd.Series([True, False, True, False, np.nan, None], name='bool')
>>> s.ads.feature_type = ['boolean']
>>> s.ads.feature_plot()
"""
Expand All @@ -155,7 +156,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:

Examples
--------
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='bool')
>>> s = pd.Series([True, False, True, False, np.nan, None], name='bool')
>>> s.ads.feature_type = ['boolean']
>>> s.ads.feature_domain()
constraints:
Expand Down
23 changes: 12 additions & 11 deletions ads/feature_engineering/feature_type/category.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*--

# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
# Copyright (c) 2021, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

"""
Expand All @@ -11,18 +10,20 @@
Category
The Category feature type.
"""

import matplotlib.pyplot as plt
import pandas as pd

from ads.common.decorator.runtime_dependency import (
OptionalDependency,
runtime_dependency,
)
from ads.feature_engineering import schema
from ads.feature_engineering.feature_type.base import FeatureType
from ads.feature_engineering.utils import (
SchemeTeal,
_count_unique_missing,
_set_seaborn_theme,
SchemeTeal,
)
from ads.feature_engineering import schema
from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
)


Expand Down Expand Up @@ -71,7 +72,7 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:
Examples
--------
>>> cat = pd.Series(['S', 'C', 'S', 'S', 'S', 'Q', 'S', 'S', 'S', 'C', 'S', 'S', 'S',
'S', 'S', 'S', 'Q', 'S', 'S', '', np.NaN, None], name='сategory')
'S', 'S', 'S', 'Q', 'S', 'S', '', np.nan, None], name='сategory')
>>> cat.ads.feature_type = ['сategory']
>>> cat.ads.feature_stat()
Metric Value
Expand Down Expand Up @@ -100,7 +101,7 @@ def feature_plot(x: pd.Series) -> plt.Axes:
Examples
--------
>>> cat = pd.Series(['S', 'C', 'S', 'S', 'S', 'Q', 'S', 'S', 'S', 'C', 'S', 'S', 'S',
'S', 'S', 'S', 'Q', 'S', 'S', '', np.NaN, None], name='сategory')
'S', 'S', 'S', 'Q', 'S', 'S', '', np.nan, None], name='сategory')
>>> cat.ads.feature_type = ['сategory']
>>> cat.ads.feature_plot()
"""
Expand All @@ -121,7 +122,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:
Examples
--------
>>> cat = pd.Series(['S', 'C', 'S', 'S', 'S', 'Q', 'S', 'S', 'S', 'C', 'S', 'S', 'S',
'S', 'S', 'S', 'Q', 'S', 'S', '', np.NaN, None], name='category')
'S', 'S', 'S', 'Q', 'S', 'S', '', np.nan, None], name='category')
>>> cat.ads.feature_type = ['category']
>>> cat.ads.feature_domain()
constraints:
Expand Down
25 changes: 13 additions & 12 deletions ads/feature_engineering/feature_type/continuous.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*--

# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
# Copyright (c) 2021, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

"""
Expand All @@ -11,19 +10,21 @@
Continuous
The Continuous feature type.
"""

import matplotlib.pyplot as plt
import pandas as pd

from ads.common.decorator.runtime_dependency import (
OptionalDependency,
runtime_dependency,
)
from ads.feature_engineering import schema
from ads.feature_engineering.feature_type.base import FeatureType
from ads.feature_engineering.utils import (
_add_missing,
_set_seaborn_theme,
SchemeTeal,
_add_missing,
_format_stat,
)
from ads.feature_engineering import schema
from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
_set_seaborn_theme,
)


Expand Down Expand Up @@ -62,7 +63,7 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:
Examples
--------
>>> cts = pd.Series([13.32, 3.32, 4.3, 2.45, 6.34, 2.25,
4.43, 3.26, np.NaN, None], name='continuous')
4.43, 3.26, np.nan, None], name='continuous')
>>> cts.ads.feature_type = ['continuous']
>>> cts.ads.feature_stat()
Metric Value
Expand Down Expand Up @@ -99,7 +100,7 @@ def feature_plot(x: pd.Series) -> plt.Axes:
Examples
--------
>>> cts = pd.Series([13.32, 3.32, 4.3, 2.45, 6.34, 2.25,
4.43, 3.26, np.NaN, None], name='continuous')
4.43, 3.26, np.nan, None], name='continuous')
>>> cts.ads.feature_type = ['continuous']
>>> cts.ads.feture_plot()

Expand All @@ -125,7 +126,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:
Examples
--------
>>> cts = pd.Series([13.32, 3.32, 4.3, 2.45, 6.34, 2.25,
4.43, 3.26, np.NaN, None], name='continuous')
4.43, 3.26, np.nan, None], name='continuous')
>>> cts.ads.feature_type = ['continuous']
>>> cts.ads.feature_domain()
constraints: []
Expand Down
23 changes: 10 additions & 13 deletions ads/feature_engineering/feature_type/datetime.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*--

# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
# Copyright (c) 2021, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

"""
Expand All @@ -11,21 +10,19 @@
DateTime
The DateTime feature type.
"""

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pandas.api.types as pdtypes
from ads.feature_engineering.feature_type.base import FeatureType
from ads.feature_engineering.utils import (
_add_missing,
_set_seaborn_theme,
SchemeTeal,
)
from ads.feature_engineering import schema

from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
runtime_dependency,
)
from ads.feature_engineering import schema
from ads.feature_engineering.feature_type.base import FeatureType
from ads.feature_engineering.utils import SchemeTeal, _add_missing, _set_seaborn_theme


def default_handler(data: pd.Series, *args, **kwargs) -> pd.Series:
Expand Down Expand Up @@ -123,12 +120,12 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:
df_stat = pd.Series(
{
"count": len(x),
"sample maximum": x.replace(r"", np.NaN).dropna().max(),
"sample minimum": x.replace(r"", np.NaN).dropna().min(),
"sample maximum": x.replace(r"", np.nan).dropna().max(),
"sample minimum": x.replace(r"", np.nan).dropna().min(),
},
name=x.name,
).to_frame()
return _add_missing(x.replace(r"", np.NaN), df_stat)
return _add_missing(x.replace(r"", np.nan), df_stat)

@staticmethod
@runtime_dependency(module="seaborn", install_from=OptionalDependency.VIZ)
Expand Down
28 changes: 15 additions & 13 deletions ads/feature_engineering/feature_type/gis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*--

# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
# Copyright (c) 2021, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

"""
Expand All @@ -11,20 +10,23 @@
GIS
The GIS feature type.
"""

import re

import matplotlib.pyplot as plt
import pandas as pd
import re

from ads.common.decorator.runtime_dependency import (
OptionalDependency,
runtime_dependency,
)
from ads.feature_engineering import schema
from ads.feature_engineering.feature_type.base import FeatureType
from ads.feature_engineering.utils import (
_count_unique_missing,
_str_lat_long_to_point,
SchemeNeutral,
SchemeTeal,
)
from ads.feature_engineering import schema
from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
_count_unique_missing,
_str_lat_long_to_point,
)

PATTERN = re.compile(r"^[(]?(\-?\d+\.\d+?),\s*(\-?\d+\.\d+?)[)]?$", re.VERBOSE)
Expand Down Expand Up @@ -126,7 +128,7 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:
"-44.510428,-169.269477",
"-56.3344375,-166.407038",
"",
np.NaN,
np.nan,
None
],
name='gis'
Expand Down Expand Up @@ -165,7 +167,7 @@ def feature_plot(x: pd.Series) -> plt.Axes:
"-44.510428,-169.269477",
"-56.3344375,-166.407038",
"",
np.NaN,
np.nan,
None
],
name='gis'
Expand Down Expand Up @@ -221,7 +223,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:
"-44.510428,-169.269477",
"-56.3344375,-166.407038",
"",
np.NaN,
np.nan,
None
],
name='gis'
Expand Down
21 changes: 11 additions & 10 deletions ads/feature_engineering/feature_type/integer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*--

# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
# Copyright (c) 2021, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

"""
Expand All @@ -11,19 +10,21 @@
Integer
The Integer feature type.
"""

import matplotlib.pyplot as plt
import pandas as pd

from ads.common.decorator.runtime_dependency import (
OptionalDependency,
runtime_dependency,
)
from ads.feature_engineering import schema
from ads.feature_engineering.feature_type.base import FeatureType
from ads.feature_engineering.utils import (
_add_missing,
_set_seaborn_theme,
SchemeTeal,
_add_missing,
_format_stat,
)
from ads.feature_engineering import schema
from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
_set_seaborn_theme,
)


Expand Down Expand Up @@ -120,7 +121,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:

Examples
--------
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='integer')
>>> s = pd.Series([True, False, True, False, np.nan, None], name='integer')
>>> s.ads.feature_type = ['integer']
>>> s.ads.feature_domain()
constraints: []
Expand Down
Loading
Loading