From ed91cb911524722a9fdf1f2e0ab72ab7de28b350 Mon Sep 17 00:00:00 2001 From: Christoph Hansknecht Date: Sat, 2 Nov 2024 11:55:41 +0100 Subject: [PATCH 1/2] Remove deprecated functions / classes --- cyipopt/cython/ipopt_wrapper.pyx | 70 -------------------------------- 1 file changed, 70 deletions(-) diff --git a/cyipopt/cython/ipopt_wrapper.pyx b/cyipopt/cython/ipopt_wrapper.pyx index b6261b4..fbd7d49 100644 --- a/cyipopt/cython/ipopt_wrapper.pyx +++ b/cyipopt/cython/ipopt_wrapper.pyx @@ -18,7 +18,6 @@ import numpy as np cimport numpy as np from cyipopt.exceptions import CyIpoptEvaluationError -from cyipopt.utils import deprecated_warning, generate_deprecation_warning_msg from ipopt cimport * __all__ = [ @@ -57,25 +56,6 @@ def set_logging_level(level=None): verbosity = level -@deprecated_warning("set_logging_level") -def setLoggingLevel(level=None): - """Function to continue support for old API. - - .. deprecated:: 1.0.0 - :func:`setLoggingLevel` will be removed in CyIpopt 1.1.0, it is replaced - by :func:`set_logging_level` because the latter complies with PEP8. - - For full documentation of this function please see - :func:`set_logging_level`. - - This function acts as a wrapper to the new :func:`set_logging_level` - function. It simply issues a :exc:`FutureWarning` to the user before - passing all args and kwargs through to :func:`set_logging_level`. - - """ - set_logging_level(level) - - set_logging_level() cdef inline void log(char* msg, int level): @@ -555,17 +535,6 @@ cdef class Problem: self.__nlp = NULL - @deprecated_warning("add_option") - def addOption(self, *args, **kwargs): - """Add a keyword/value option pair to the problem. - - .. deprecated:: 1.0.0 - :meth:`addOption` will be removed in CyIpopt 1.1.0, it is replaced - by :meth:`add_option` because the latter complies with PEP8. - - """ - return self.add_option(*args, **kwargs) - def add_option(self, keyword, val): """Add a keyword/value option pair to the problem. @@ -598,18 +567,6 @@ cdef class Problem: if not ret_val: raise TypeError("Error while assigning an option") - @deprecated_warning("set_problem_scaling") - def setProblemScaling(self, *args, **kwargs): - """Optional function for setting scaling parameters for the problem. - - .. deprecated:: 1.0.0 - :meth:`setProblemScaling` will be removed in CyIpopt 1.1.0, it is - replaced by :meth:`set_problem_scaling` because the latter complies - with PEP8. - - """ - return self.set_problem_scaling(*args, **kwargs) - def set_problem_scaling(self, obj_scaling=1.0, x_scaling=None, g_scaling=None): """Optional function for setting scaling parameters for the problem. @@ -1394,30 +1351,3 @@ cdef Bool intermediate_cb(Index alg_mod, return True return ret_val - - -class problem(Problem): - """Class to continue support for old API. - - .. deprecated:: 1.0.0 - :class:`problem` will be removed in CyIpopt 1.1.0, it is replaced by - :class:`Problem` because the latter complies with PEP8. - - For full documentation of this class including its attributes and methods - please see :class:`Problem`. - - This class acts as a wrapper to the new :class:`Problem` class. It simply - issues a :exc:`FutureWarning` to the user before passing all args and - kwargs through to :class:`Problem`. - - Returns - ------- - :obj:`Problem` - Instance created with the `args` and `kwargs` parameters. - - """ - - def __new__(cls, *args, **kwargs): - msg = generate_deprecation_warning_msg("class", "problem", "Problem") - warnings.warn(msg, FutureWarning) - return super(problem, cls).__new__(cls, *args, **kwargs) From cabe5ee1e34270995367e6157f53f6b1d1c7fb08 Mon Sep 17 00:00:00 2001 From: Christoph Hansknecht Date: Sat, 2 Nov 2024 15:55:04 +0100 Subject: [PATCH 2/2] Remove deprecation tests --- cyipopt/cython/ipopt_wrapper.pyx | 2 +- cyipopt/tests/unit/test_deprecations.py | 87 ------------------------- 2 files changed, 1 insertion(+), 88 deletions(-) diff --git a/cyipopt/cython/ipopt_wrapper.pyx b/cyipopt/cython/ipopt_wrapper.pyx index fbd7d49..827ef6f 100644 --- a/cyipopt/cython/ipopt_wrapper.pyx +++ b/cyipopt/cython/ipopt_wrapper.pyx @@ -21,7 +21,7 @@ from cyipopt.exceptions import CyIpoptEvaluationError from ipopt cimport * __all__ = [ - "set_logging_level", "setLoggingLevel", "Problem", "problem", "IPOPT_VERSION" + "set_logging_level", "Problem", "IPOPT_VERSION" ] IPOPT_VERSION = (IPOPT_VERSION_MAJOR, IPOPT_VERSION_MINOR, IPOPT_VERSION_RELEASE) diff --git a/cyipopt/tests/unit/test_deprecations.py b/cyipopt/tests/unit/test_deprecations.py index ebf56b3..fe1772b 100644 --- a/cyipopt/tests/unit/test_deprecations.py +++ b/cyipopt/tests/unit/test_deprecations.py @@ -20,90 +20,3 @@ def test_ipopt_import_deprecation(): "release.") with pytest.warns(FutureWarning, match=expected_warning_msg): import ipopt - - -def test_non_pep8_class_name_deprecation(hs071_definition_instance_fixture, - hs071_initial_guess_fixture, - hs071_variable_lower_bounds_fixture, - hs071_variable_upper_bounds_fixture, - hs071_constraint_lower_bounds_fixture, - hs071_constraint_upper_bounds_fixture, - ): - """Ensure use of old non-PEP8 classes API raises FutureWarning to user.""" - expected_warning_msg = ("The class named 'problem' will soon be " - "deprecated in CyIpopt. Please replace all uses " - "and use 'Problem' going forward.") - with pytest.warns(FutureWarning, match=expected_warning_msg): - _ = cyipopt.problem(n=len(hs071_initial_guess_fixture), - m=len(hs071_constraint_lower_bounds_fixture), - problem_obj=hs071_definition_instance_fixture, - lb=hs071_variable_lower_bounds_fixture, - ub=hs071_variable_upper_bounds_fixture, - cl=hs071_constraint_lower_bounds_fixture, - cu=hs071_constraint_upper_bounds_fixture, - ) - - -def test_non_pep8_set_logging_level_deprecation(): - """Ensure use of old non-PEP8 classes API raises FutureWarning to user.""" - expected_warning_msg = ("The function named 'setLoggingLevel' will soon " - "be deprecated in CyIpopt. Please replace all " - "uses and use 'set_logging_level' going forward.") - with pytest.warns(FutureWarning, match=expected_warning_msg): - cyipopt.setLoggingLevel() - - -def test_non_pep8_method_names_deprecation(hs071_problem_instance_fixture): - """Ensure use of old non-PEP8 methods API raises FutureWarning to user.""" - nlp = hs071_problem_instance_fixture - - assert isinstance(nlp, cyipopt.Problem) - - expected_warning_msg = "" - with pytest.warns(FutureWarning, match=expected_warning_msg): - nlp.addOption("mu_strategy", "adaptive") - - expected_warning_msg = "" - with pytest.warns(FutureWarning, match=expected_warning_msg): - nlp.setProblemScaling(obj_scaling=2.0) - - -def test_deprecated_problem_can_be_subclassed(): - """`problem` can be subclassed and its args/kwargs changed.""" - - class SubclassedProblem(cyipopt.problem): - - def __init__(self, *args, **kwargs): - n = args[0] - m = args[1] - problem_obj = kwargs.get("problem_obj") - lb = kwargs.get("lb") - ub = kwargs.get("ub") - cl = kwargs.get("cl") - cu = kwargs.get("cu") - super(SubclassedProblem, self).__init__(n, - m, - problem_obj=problem_obj, - lb=lb, - ub=ub, - cl=cl, - cu=cu) - - def objective(self): - pass - - def gradient(self): - pass - - def constraints(self): - pass - - def jacobian(self): - pass - - expected_warning_msg = ("The class named 'problem' will soon be " - "deprecated in CyIpopt. Please replace all uses " - "and use 'Problem' going forward.") - with pytest.warns(FutureWarning, match=expected_warning_msg): - _ = SubclassedProblem(2, 2, None, None, problem_obj=None, lb=None, - ub=None, cl=[0, 0], cu=[0, 0], other_kwarg=None)