Skip to content

Commit

Permalink
replace warnings.warning
Browse files Browse the repository at this point in the history
Signed-off-by: xadupre <[email protected]>
  • Loading branch information
xadupre committed Sep 4, 2024
1 parent f37f2d6 commit e8870bd
Show file tree
Hide file tree
Showing 27 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion benchmarks/bench_plot_onnxruntime_hgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def bench(
try:
assert_almost_equal(p1.ravel(), p2.ravel(), decimal=5)
except AssertionError as e:
warnings.warning(str(e))
warning.warn(str(e))
return res


Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_plot_onnxruntime_linreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def bench(n_obs, n_features, fit_intercepts, methods, repeat=10, verbose=False):
try:
assert_almost_equal(p1.ravel(), p2.ravel(), decimal=5)
except AssertionError as e:
warnings.warning(str(e))
warning.warn(str(e))
return res


Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_plot_onnxruntime_random_forest_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def bench(
p1.ravel(), p2.ravel(), decimal=5
)
except AssertionError as e:
warnings.warning(str(e))
warning.warn(str(e))
return res


Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_plot_onnxruntime_svm_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def bench(n_obs, n_features, kernels, methods, repeat=10, verbose=False):
try:
assert_almost_equal(p1.ravel(), p2.ravel(), decimal=3)
except AssertionError as e:
warnings.warning(str(e))
warning.warn(str(e))
return res


Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/plot_gexternal_lightgbm_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def skl2onnx_convert_lightgbm(scope, operator, container):
options = scope.get_options(operator.raw_operator)
if "split" in options:
if pv.Version(oml_version) < pv.Version("1.9.2"):
warnings.warning(
warning.warn(
"Option split was released in version 1.9.2 but %s is "
"installed. It will be ignored." % oml_version
)
Expand Down
4 changes: 2 additions & 2 deletions skl2onnx/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _parse_sklearn_simple_model(scope, model, inputs, custom_parsers=None, alias
try:
names = parser_names(scope=scope, inputs=inputs)
except TypeError as e:
warnings.warning(
warning.warn(
"Calling parser %r for model type %r failed due to %r. "
"This warnings will become an exception in version 1.11. "
"The parser signature should parser(scope=None, "
Expand Down Expand Up @@ -560,7 +560,7 @@ def _parse_sklearn_classifier(scope, model, inputs, custom_parsers=None):
def _parse_sklearn_multi_output_classifier(scope, model, inputs, custom_parsers=None):
options = scope.get_options(model, dict(zipmap=True))
if options["zipmap"]:
warnings.warning(
warning.warn(
"Option zipmap is ignored for model %r. "
"Set option zipmap to False to "
"remove this message." % type(model),
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/_supported_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def update_registered_converter(
and model in sklearn_operator_name_map
and alias != sklearn_operator_name_map[model]
):
warnings.warning(
warning.warn(
"Model '{0}' was already registered under alias "
"'{1}'.".format(model, sklearn_operator_name_map[model])
)
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/algebra/onnx_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ class OnnxSubOperator(OnnxSubEstimator):

def __init__(self, *args, **kwargs):
OnnxSubEstimator.__init__(self, *args, **kwargs)
warnings.warning(
warning.warn(
(
"Class OnnxSubOperator will be removed in 1.10. "
"It should be replaced by OnnxSubEstimator."
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/algebra/onnx_operator_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def converter(
target_opset=op_version, outputs=outputs, options=options
)
except TypeError:
warnings.warning(
warning.warn(
"Signature should be to_onnx_operator(self, inputs=None, "
"outputs=None, target_opset=None, **kwargs). "
"This will be the case in version 1.11, class=%r."
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/common/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def _get_op_version(self, domain, op_type):
# avoid a not necessarily necessary warning
vers = 1
else:
warnings.warning(
warning.warn(
"Unable to find operator '{}' in domain '{}' in ONNX, "
"op_version is forced to 1.".format(op_type, domain)
)
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/common/_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ def convert_topology(
".".format(onnx_target_opset, found)
)
if onnx_target_opset > get_latest_tested_opset_version():
warnings.warning(
warning.warn(
"Parameter target_opset {} > {} is higher than the "
"the latest tested version"
".".format(onnx_target_opset, get_latest_tested_opset_version())
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def convert_sklearn(
if name is None:
name = str(uuid4().hex)
if dtype is not None:
warnings.warning(
warning.warn(
"Parameter dtype is no longer supported. It will be removed in 1.9.0.",
DeprecationWarning,
)
Expand Down
4 changes: 2 additions & 2 deletions skl2onnx/helpers/investigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def decision_function(self, X, *args, **kwargs):
try:
setattr(model, k, MethodType(new_methods[k], model))
except AttributeError:
warnings.warning(
warning.warn(
"Unable to overwrite method '{}' for class "
"{}.".format(k, type(model))
)
Expand All @@ -217,7 +217,7 @@ def decision_function(self, X, *args, **kwargs):
try:
setattr(skl_model, k, MethodType(new_methods[k], skl_model))
except AttributeError:
warnings.warning(
warning.warn(
"Unable to overwrite method '{}' for class "
"{}.".format(k, type(skl_model))
)
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/operator_converters/local_outlier_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def convert_sklearn_local_outlier_factor(
kwargs = {}
if op.p != 2:
if options["optim"] == "cdist":
warnings.warning(
warning.warn(
"Option p=%r may not be compatible with the runtime. "
"See https://github.com/microsoft/onnxruntime/blob/main/"
"docs/ContribOperators.md#com.microsoft.CDist."
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/operator_converters/text_vectoriser.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def convert_sklearn_text_vectorizer(
"https://github.com/onnx/sklearn-onnx/issues."
)
if op.analyzer == "char":
warnings.warning(
warning.warn(
"The conversion of CountVectorizer may not work. "
"only tokenizer='word' is fully supported. "
"You may raise an issue at "
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/sklapi/woe_transformer_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def onnx_attributes(self):
)
)
if len(atts["target_weights"]) != len(set(atts["target_weights"])):
warnings.warning(
warning.warn(
"All targets should be unique %r." % atts["target_weights"],
stacklevel=0,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run_all_tests(folder=None, verbose=True):
try:
import onnxmltools # noqa: F401
except ImportError:
warnings.warning("Cannot import onnxmltools. Some tests won't work.")
warning.warn("Cannot import onnxmltools. Some tests won't work.")

this = os.path.abspath(os.path.dirname(__file__))
subs = [this]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_algebra_onnx_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def test_onnxt_runtime_pad(self):
try:
assert_almost_equal(exp, got[0])
except AssertionError as e:
warnings.warning(e)
warning.warn(e)

data = np.array([[1.0, 1.2], [2.3, 3.4], [4.5, 5.7]], dtype=np.float32)
pads = np.array([0, 2, 0, 0], dtype=np.int64)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_algebra_onnx_operators_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_onnx_example_pdist(self):
onnx.checker.check_model(model_def)
except ValidationError as e:
if pv.Version(onnx__version__) <= pv.Version("1.5.0"):
warnings.warning(e)
warning.warn(e)
else:
raise e

Expand Down
2 changes: 1 addition & 1 deletion tests/test_algebra_onnx_operators_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_onnx_init_sparse_coo(self):
res = sess.run(None, {"X": X.todense()})[0]
except RuntimeError as e:
# Sparse tensor is not supported for constant.
warnings.warning(
warning.warn(
"Unable to run with %r\n---\n%s\n%s" % ({"X": X}, model_def, e)
)
return
Expand Down
2 changes: 1 addition & 1 deletion tests/test_algebra_symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from skl2onnx.algebra.onnx_ops import OnnxAbs, OnnxNormalizer, OnnxArgMin
from skl2onnx.algebra.onnx_ops import OnnxSplitApi18, OnnxScaler
except ImportError:
warnings.warning("Unable to test OnnxAbs, OnnxNormalizer, OnnxArgMin, OnnxSplit.")
warning.warn("Unable to test OnnxAbs, OnnxNormalizer, OnnxArgMin, OnnxSplit.")
OnnxAbs = None
from test_utils import TARGET_OPSET, InferenceSessionEx as InferenceSession

Expand Down
4 changes: 2 additions & 2 deletions tests/test_sklearn_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_pipeline_tfidf(self):
random_state=1, subset="test", categories=categories
)
except urllib.error.URLError:
warnings.warning("Unit test may fail due to connectivity issue.")
warning.warn("Unit test may fail due to connectivity issue.")
return
train_data = SubjectBodyExtractor().fit_transform(train.data)
tfi = TfidfVectorizer(min_df=30)
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_pipeline_tfidf_pipeline_minmax(self):
random_state=1, subset="train", categories=categories
)
except urllib.error.URLError:
warnings.warning("Unit test may fail due to connectivity issue.")
warning.warn("Unit test may fail due to connectivity issue.")
return
train_data = SubjectBodyExtractor().fit_transform(train.data)
pipeline = Pipeline(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sklearn_gaussian_process_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ def test_gpr_rbf_fitted_return_std_exp_sine_squared_double_true(self):
gp.fit(Xtrain_, Ytrain_)
except (AttributeError, TypeError) as e:
# unstable issue fixed with scikit-learn>=0.24
warnings.warning(
warning.warn(
"Training did not converge but fails at raising a warning: %r." % e
)
return
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sklearn_nearest_neighbour_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def test_model_knn_regressor2_1_radius(self):
# One broadcasted multiplication unexpectedly produces nan.
whole = "\n".join(rows)
if "[ nan" in whole:
warnings.warning(whole)
warning.warn(whole)
return
raise AssertionError(whole)
if ort_version.startswith("1.3.") and sys.platform == "win32":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sklearn_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def test_pipeline_column_transformer_titanic(self):
data = pandas.read_csv(titanic_url)
except url_error.URLError:
# Do not fail the test if the data cannot be fetched.
warnings.warning("Unable to fetch titanic data.")
warning.warn("Unable to fetch titanic data.")
return
X = data.drop("survived", axis=1)
y = data["survived"]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils/tests_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,15 @@ def lambda_original():
except OnnxRuntimeMissingNewOnnxOperatorException as e:
if fail_evenif_notimplemented:
raise e
warnings.warning(str(e))
warning.warn(str(e))
continue
except AssertionError as e:
if dump_error_log:
with open(error_dump, "w", encoding="utf-8") as f:
f.write(str(e) + "\n--------------\n")
traceback.print_exc(file=f)
if isinstance(allow, bool) and allow:
warnings.warning(
warning.warn(
"Issue with '{0}' due to {1}".format(
basename, str(e).replace("\n", " -- ")
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/utils_backend_onnxruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def compare_runtime(
try:
import onnxruntime
except ImportError:
warnings.warning("Unable to import onnxruntime.")
warning.warn("Unable to import onnxruntime.")
return None

if verbose:
Expand Down

0 comments on commit e8870bd

Please sign in to comment.