8000 Revert the use of attributes in check_is_fitted · fatiando/verde@d87ffd7 · GitHub
[go: up one dir, main page]

Skip to content

Commit d87ffd7

Browse files
authored
Revert the use of attributes in check_is_fitted
Rollback the changes in #217 because scikit-learn reverted the deprecation of attributes in check_is_fitted. See scikit-learn/scikit-learn#15947
1 parent 34cf8d7 commit d87ffd7

File tree

6 files changed

+7
-11
lines changed

6 files changed

+7
-11
lines changed

verde/base/base_classes.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,12 @@ class BaseGridder(BaseEstimator):
5454
... if self.multiplier <= 0:
5555
... raise ValueError('Invalid multiplier {}'
5656
... .format(self.multiplier))
57-
... # Use a trailing underscore on the mean so we could
58-
... # know if the gridder is already fitted before predicting
5957
... self.mean_ = data.mean()*self.multiplier
6058
... # fit should return self so that we can chain operations
6159
... return self
6260
... def predict(self, coordinates):
63-
... # We know the gridder has been fitted if it has the mean_
64-
... # attribute (or if the gridder has any attribute with a
65-
... # trailing underscore)
66-
... check_is_fitted(self)
61+
... # We know the gridder has been fitted if it has the mean
62+
... check_is_fitted(self, ['mean_'])
6763
... return np.ones_like(coordinates[0])*self.mean_
6864
>>> # Try it on some synthetic data
6965
>>> synthetic = vd.datasets.CheckerBoard(region=(0, 5, -10, 8))

verde/chain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def predict(self, coordinates):
118118
The data values predicted on the given points.
119119
120120
"""
121-
check_is_fitted(self)
121+
check_is_fitted(self, ["region_"])
122122
result = None
123123
for _, step in self.steps:
124124
if hasattr(step, "predict"):

verde/scipygridder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ def predict(self, coordinates):
131131
The data values interpolated on the given points.
132132
133133
"""
134-
check_is_fitted(self)
134+
check_is_fitted(self, ["interpolator_"])
135135
easting, northing = coordinates[:2]
136136
return self.interpolator_((easting, northing))

verde/spline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def predict(self, coordinates):
231231
The data values evaluated on the given points.
232232
233233
"""
234-
check_is_fitted(self)
234+
check_is_fitted(self, ["_best"])
235235
return self._best.predict(coordinates)
236236

237237

verde/trend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def predict(self, coordinates):
149149
The trend values evaluated on the given points.
150150
151151
"""
152-
check_is_fitted(self)
152+
check_is_fitted(self, ["coef_"])
153153
easting, northing = n_1d_arrays(coordinates, 2)
154154
shape = np.broadcast(*coordinates[:2]).shape
155155
data = np.zeros(easting.size, dtype=easting.dtype)

verde/vector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def predict(self, coordinates):
138138
:meth:`~verde.Vector.fit`.
139139
140140
"""
141-
check_is_fitted(self)
141+
check_is_fitted(self, ["region_"])
142142
return tuple(comp.predict(coordinates) for comp in self.components)
143143

144144

0 commit comments

Comments
 (0)
0