Skip to content

Commit f003644

Browse files
authored
Relaxes matplotlib dependency (#1227)
1 parent e2fb636 commit f003644

28 files changed

+281
-250
lines changed

ads/common/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,7 @@ def default(self, obj):
782782
),
783783
):
784784
return int(obj)
785-
elif isinstance(
786-
obj, (np.float_, np.float16, np.float32, np.float64, np.double)
787-
):
785+
elif isinstance(obj, (np.float16, np.float32, np.float64, np.double)):
788786
return float(obj)
789787
elif isinstance(obj, (np.ndarray,)):
790788
return obj.tolist()

ads/feature_engineering/feature_type/boolean.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

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

76
"""
@@ -15,19 +14,21 @@
1514
default_handler(data: pd.Series) -> pd.Series
1615
Processes given data and indicates if the data matches requirements.
1716
"""
17+
1818
import matplotlib.pyplot as plt
1919
import pandas as pd
20+
21+
from ads.common.decorator.runtime_dependency import (
22+
OptionalDependency,
23+
runtime_dependency,
24+
)
25+
from ads.feature_engineering import schema
2026
from ads.feature_engineering.feature_type.base import FeatureType
2127
from ads.feature_engineering.utils import (
28+
SchemeTeal,
2229
_count_unique_missing,
23-
is_boolean,
2430
_set_seaborn_theme,
25-
SchemeTeal,
26-
)
27-
from ads.feature_engineering import schema
28-
from ads.common.decorator.runtime_dependency import (
29-
runtime_dependency,
30-
OptionalDependency,
31+
is_boolean,
3132
)
3233

3334

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

4950

5051
class Boolean(FeatureType):
@@ -74,7 +75,7 @@ class Boolean(FeatureType):
7475
>>> from ads.feature_engineering.feature_type.boolean import Boolean
7576
>>> import pandas as pd
7677
>>> import numpy as np
77-
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='bool')
78+
>>> s = pd.Series([True, False, True, False, np.nan, None], name='bool')
7879
>>> s.ads.feature_type = ['boolean']
7980
>>> Boolean.validator.is_boolean(s)
8081
0 True
@@ -106,7 +107,7 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:
106107
107108
Examples
108109
--------
109-
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='bool')
110+
>>> s = pd.Series([True, False, True, False, np.nan, None], name='bool')
110111
>>> s.ads.feature_type = ['boolean']
111112
>>> s.ads.feature_stat()
112113
Metric Value
@@ -134,7 +135,7 @@ def feature_plot(x: pd.Series) -> plt.Axes:
134135
135136
Examples
136137
--------
137-
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='bool')
138+
>>> s = pd.Series([True, False, True, False, np.nan, None], name='bool')
138139
>>> s.ads.feature_type = ['boolean']
139140
>>> s.ads.feature_plot()
140141
"""
@@ -155,7 +156,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:
155156
156157
Examples
157158
--------
158-
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='bool')
159+
>>> s = pd.Series([True, False, True, False, np.nan, None], name='bool')
159160
>>> s.ads.feature_type = ['boolean']
160161
>>> s.ads.feature_domain()
161162
constraints:

ads/feature_engineering/feature_type/category.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

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

76
"""
@@ -11,18 +10,20 @@
1110
Category
1211
The Category feature type.
1312
"""
13+
1414
import matplotlib.pyplot as plt
1515
import pandas as pd
16+
17+
from ads.common.decorator.runtime_dependency import (
18+
OptionalDependency,
19+
runtime_dependency,
20+
)
21+
from ads.feature_engineering import schema
1622
from ads.feature_engineering.feature_type.base import FeatureType
1723
from ads.feature_engineering.utils import (
24+
SchemeTeal,
1825
_count_unique_missing,
1926
_set_seaborn_theme,
20-
SchemeTeal,
21-
)
22-
from ads.feature_engineering import schema
23-
from ads.common.decorator.runtime_dependency import (
24-
runtime_dependency,
25-
OptionalDependency,
2627
)
2728

2829

@@ -71,7 +72,7 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:
7172
Examples
7273
--------
7374
>>> cat = pd.Series(['S', 'C', 'S', 'S', 'S', 'Q', 'S', 'S', 'S', 'C', 'S', 'S', 'S',
74-
'S', 'S', 'S', 'Q', 'S', 'S', '', np.NaN, None], name='сategory')
75+
'S', 'S', 'S', 'Q', 'S', 'S', '', np.nan, None], name='сategory')
7576
>>> cat.ads.feature_type = ['сategory']
7677
>>> cat.ads.feature_stat()
7778
Metric Value
@@ -100,7 +101,7 @@ def feature_plot(x: pd.Series) -> plt.Axes:
100101
Examples
101102
--------
102103
>>> cat = pd.Series(['S', 'C', 'S', 'S', 'S', 'Q', 'S', 'S', 'S', 'C', 'S', 'S', 'S',
103-
'S', 'S', 'S', 'Q', 'S', 'S', '', np.NaN, None], name='сategory')
104+
'S', 'S', 'S', 'Q', 'S', 'S', '', np.nan, None], name='сategory')
104105
>>> cat.ads.feature_type = ['сategory']
105106
>>> cat.ads.feature_plot()
106107
"""
@@ -121,7 +122,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:
121122
Examples
122123
--------
123124
>>> cat = pd.Series(['S', 'C', 'S', 'S', 'S', 'Q', 'S', 'S', 'S', 'C', 'S', 'S', 'S',
124-
'S', 'S', 'S', 'Q', 'S', 'S', '', np.NaN, None], name='category')
125+
'S', 'S', 'S', 'Q', 'S', 'S', '', np.nan, None], name='category')
125126
>>> cat.ads.feature_type = ['category']
126127
>>> cat.ads.feature_domain()
127128
constraints:

ads/feature_engineering/feature_type/continuous.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

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

76
"""
@@ -11,19 +10,21 @@
1110
Continuous
1211
The Continuous feature type.
1312
"""
13+
1414
import matplotlib.pyplot as plt
1515
import pandas as pd
16+
17+
from ads.common.decorator.runtime_dependency import (
18+
OptionalDependency,
19+
runtime_dependency,
20+
)
21+
from ads.feature_engineering import schema
1622
from ads.feature_engineering.feature_type.base import FeatureType
1723
from ads.feature_engineering.utils import (
18-
_add_missing,
19-
_set_seaborn_theme,
2024
SchemeTeal,
25+
_add_missing,
2126
_format_stat,
22-
)
23-
from ads.feature_engineering import schema
24-
from ads.common.decorator.runtime_dependency import (
25-
runtime_dependency,
26-
OptionalDependency,
27+
_set_seaborn_theme,
2728
)
2829

2930

@@ -62,7 +63,7 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:
6263
Examples
6364
--------
6465
>>> cts = pd.Series([13.32, 3.32, 4.3, 2.45, 6.34, 2.25,
65-
4.43, 3.26, np.NaN, None], name='continuous')
66+
4.43, 3.26, np.nan, None], name='continuous')
6667
>>> cts.ads.feature_type = ['continuous']
6768
>>> cts.ads.feature_stat()
6869
Metric Value
@@ -99,7 +100,7 @@ def feature_plot(x: pd.Series) -> plt.Axes:
99100
Examples
100101
--------
101102
>>> cts = pd.Series([13.32, 3.32, 4.3, 2.45, 6.34, 2.25,
102-
4.43, 3.26, np.NaN, None], name='continuous')
103+
4.43, 3.26, np.nan, None], name='continuous')
103104
>>> cts.ads.feature_type = ['continuous']
104105
>>> cts.ads.feture_plot()
105106
@@ -125,7 +126,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:
125126
Examples
126127
--------
127128
>>> cts = pd.Series([13.32, 3.32, 4.3, 2.45, 6.34, 2.25,
128-
4.43, 3.26, np.NaN, None], name='continuous')
129+
4.43, 3.26, np.nan, None], name='continuous')
129130
>>> cts.ads.feature_type = ['continuous']
130131
>>> cts.ads.feature_domain()
131132
constraints: []

ads/feature_engineering/feature_type/datetime.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

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

76
"""
@@ -11,21 +10,19 @@
1110
DateTime
1211
The DateTime feature type.
1312
"""
13+
1414
import matplotlib.pyplot as plt
1515
import numpy as np
1616
import pandas as pd
1717
import pandas.api.types as pdtypes
18-
from ads.feature_engineering.feature_type.base import FeatureType
19-
from ads.feature_engineering.utils import (
20-
_add_missing,
21-
_set_seaborn_theme,
22-
SchemeTeal,
23-
)
24-
from ads.feature_engineering import schema
18+
2519
from ads.common.decorator.runtime_dependency import (
26-
runtime_dependency,
2720
OptionalDependency,
21+
runtime_dependency,
2822
)
23+
from ads.feature_engineering import schema
24+
from ads.feature_engineering.feature_type.base import FeatureType
25+
from ads.feature_engineering.utils import SchemeTeal, _add_missing, _set_seaborn_theme
2926

3027

3128
def default_handler(data: pd.Series, *args, **kwargs) -> pd.Series:
@@ -123,12 +120,12 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:
123120
df_stat = pd.Series(
124121
{
125122
"count": len(x),
126-
"sample maximum": x.replace(r"", np.NaN).dropna().max(),
127-
"sample minimum": x.replace(r"", np.NaN).dropna().min(),
123+
"sample maximum": x.replace(r"", np.nan).dropna().max(),
124+
"sample minimum": x.replace(r"", np.nan).dropna().min(),
128125
},
129126
name=x.name,
130127
).to_frame()
131-
return _add_missing(x.replace(r"", np.NaN), df_stat)
128+
return _add_missing(x.replace(r"", np.nan), df_stat)
132129

133130
@staticmethod
134131
@runtime_dependency(module="seaborn", install_from=OptionalDependency.VIZ)

ads/feature_engineering/feature_type/gis.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

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

76
"""
@@ -11,20 +10,23 @@
1110
GIS
1211
The GIS feature type.
1312
"""
13+
14+
import re
15+
1416
import matplotlib.pyplot as plt
1517
import pandas as pd
16-
import re
18+
19+
from ads.common.decorator.runtime_dependency import (
20+
OptionalDependency,
21+
runtime_dependency,
22+
)
23+
from ads.feature_engineering import schema
1724
from ads.feature_engineering.feature_type.base import FeatureType
1825
from ads.feature_engineering.utils import (
19-
_count_unique_missing,
20-
_str_lat_long_to_point,
2126
SchemeNeutral,
2227
SchemeTeal,
23-
)
24-
from ads.feature_engineering import schema
25-
from ads.common.decorator.runtime_dependency import (
26-
runtime_dependency,
27-
OptionalDependency,
28+
_count_unique_missing,
29+
_str_lat_long_to_point,
2830
)
2931

3032
PATTERN = re.compile(r"^[(]?(\-?\d+\.\d+?),\s*(\-?\d+\.\d+?)[)]?$", re.VERBOSE)
@@ -126,7 +128,7 @@ def feature_stat(x: pd.Series) -> pd.DataFrame:
126128
"-44.510428,-169.269477",
127129
"-56.3344375,-166.407038",
128130
"",
129-
np.NaN,
131+
np.nan,
130132
None
131133
],
132134
name='gis'
@@ -165,7 +167,7 @@ def feature_plot(x: pd.Series) -> plt.Axes:
165167
"-44.510428,-169.269477",
166168
"-56.3344375,-166.407038",
167169
"",
168-
np.NaN,
170+
np.nan,
169171
None
170172
],
171173
name='gis'
@@ -221,7 +223,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:
221223
"-44.510428,-169.269477",
222224
"-56.3344375,-166.407038",
223225
"",
224-
np.NaN,
226+
np.nan,
225227
None
226228
],
227229
name='gis'

ads/feature_engineering/feature_type/integer.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

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

76
"""
@@ -11,19 +10,21 @@
1110
Integer
1211
The Integer feature type.
1312
"""
13+
1414
import matplotlib.pyplot as plt
1515
import pandas as pd
16+
17+
from ads.common.decorator.runtime_dependency import (
18+
OptionalDependency,
19+
runtime_dependency,
20+
)
21+
from ads.feature_engineering import schema
1622
from ads.feature_engineering.feature_type.base import FeatureType
1723
from ads.feature_engineering.utils import (
18-
_add_missing,
19-
_set_seaborn_theme,
2024
SchemeTeal,
25+
_add_missing,
2126
_format_stat,
22-
)
23-
from ads.feature_engineering import schema
24-
from ads.common.decorator.runtime_dependency import (
25-
runtime_dependency,
26-
OptionalDependency,
27+
_set_seaborn_theme,
2728
)
2829

2930

@@ -120,7 +121,7 @@ def feature_domain(cls, x: pd.Series) -> schema.Domain:
120121
121122
Examples
122123
--------
123-
>>> s = pd.Series([True, False, True, False, np.NaN, None], name='integer')
124+
>>> s = pd.Series([True, False, True, False, np.nan, None], name='integer')
124125
>>> s.ads.feature_type = ['integer']
125126
>>> s.ads.feature_domain()
126127
constraints: []

0 commit comments

Comments
 (0)