Skip to content
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

Remove deprecated functions / classes #275

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
72 changes: 1 addition & 71 deletions cyipopt/cython/ipopt_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ 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__ = [
"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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
87 changes: 0 additions & 87 deletions cyipopt/tests/unit/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading