Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ coverage:
target: auto # use the coverage from the base commit, fail if coverage is lower
threshold: 0% # allow the coverage to drop by

ignore:
- "tests/test_speed.py" # ignore performance testing in test coverage.

comment:
layout: " diff, flags, files"
behavior: default
Expand Down
2 changes: 1 addition & 1 deletion docs/source/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ can be adapted as::
setter = SimpleAtom.set, attr = "x")

Thus, when ``xpar.getValue()`` is called, it in turn calls
``SimpleAtom.get(atom, "x")``. ``xpar.setValue(value)`` calls
``SimpleAtom.get(atom, "x")``. ``xpar.set_value(value)`` calls
``SimpleAtom.set(atom, "x", value)``.

If the attributes of an object cannot be accessed in one of these three ways,
Expand Down
23 changes: 23 additions & 0 deletions news/setvalue-dep.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Added ``set_value`` method to ``diffpy.srfit.fitbase.Parameter``.

**Changed:**

* <news item>

**Deprecated:**

* Deprecated ``setValue`` method in ``diffpy.srfit.fitbase.Parameter`` for removal in 4.0.0.

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
8 changes: 4 additions & 4 deletions src/diffpy/srfit/equation/equationmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
these! > b = Argument(name="b") > add.addLiteral(a) > add.addLiteral(b)
> # make an Equation instance and pass the root > eq = Equation(root =
add) > eq(a=3, b=4) # returns 7 > eq(a=2) # remembers b=4, returns 6 >
eq.a.setValue(-3) > eq.b.setValue(3) > eq() # uses last assignment of a
and b, returns 0
eq.a.set_value(-3) > eq.b.set_value(3) > eq() # uses last assignment of
a and b, returns 0

See the class documentation for more information.
"""
Expand Down Expand Up @@ -193,14 +193,14 @@ def __call__(self, *args, **kw):
if idx >= len(self.argdict):
raise ValueError("Too many arguments")
arg = self.args[idx]
arg.setValue(val)
arg.set_value(val)

# Process kw
for name, val in kw.items():
arg = self.argdict.get(name)
if arg is None:
raise ValueError("No argument named '%s' here" % name)
arg.setValue(val)
arg.set_value(val)

self._value = self.root.getValue()
return self._value
Expand Down
74 changes: 58 additions & 16 deletions src/diffpy/srfit/equation/literals/abcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@

__all__ = ["LiteralABC", "ArgumentABC", "OperatorABC"]

from abc import ABC, abstractmethod

from abc import ABCMeta, abstractmethod, abstractproperty

import six


@six.add_metaclass(ABCMeta)
class LiteralABC(object):
class LiteralABC(ABC):
"""Abstract Base Class for Literal.

See Literal for usage.
"""

@abstractmethod
def identify(self, visitor):
"""Identify this literal using a visitor."""
pass

@abstractmethod
def getValue(self):
"""Return the value of the literal."""
pass

name = abstractproperty(None, None)
@property
@abstractmethod
def name(self):
"""Name of the literal."""
pass


# End class LiteralABC
Expand All @@ -50,11 +52,21 @@ class ArgumentABC(LiteralABC):
"""

@abstractmethod
def setValue(self, value):
def set_value(self, value):
"""Set the value of the argument."""
pass

const = abstractproperty(None, None)
value = abstractproperty(None, None)
@property
@abstractmethod
def const(self):
"""Whether the argument is constant."""
pass

@property
@abstractmethod
def value(self):
"""Value of the argument."""
pass


# End class ArgumentABC
Expand All @@ -68,14 +80,44 @@ class OperatorABC(LiteralABC):

@abstractmethod
def addLiteral(self, literal):
"""Add a literal argument to the operator."""
pass

@property
@abstractmethod
def args(self):
"""Arguments of the operator."""
pass

@property
@abstractmethod
def nin(self):
"""Number of input arguments."""
pass

args = abstractproperty(None, None)
nin = abstractproperty(None, None)
nout = abstractproperty(None, None)
operation = abstractproperty(None, None)
symbol = abstractproperty(None, None)
value = abstractproperty(None, None)
@property
@abstractmethod
def nout(self):
"""Number of outputs."""
pass

@property
@abstractmethod
def operation(self):
"""Callable implementing the operator."""
pass

@property
@abstractmethod
def symbol(self):
"""Symbol representing the operator."""
pass

@property
@abstractmethod
def value(self):
"""Value produced by the operator."""
pass


# End class OperatorABC
8 changes: 4 additions & 4 deletions src/diffpy/srfit/equation/literals/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class Argument(Literal, ArgumentABC):
A flag indicating whether this is considered a constant.
Constants may be given special treatment by the Visitors.
_value
The value of the Argument. Modified with 'setValue'.
The value of the Argument. Modified with 'set_value'.
value
Property for 'getValue' and 'setValue'.
Property for 'getValue' and 'set_value'.
"""

const = None
Expand All @@ -59,7 +59,7 @@ def getValue(self):
"""Get the value of this Literal."""
return self._value

def setValue(self, val):
def set_value(self, val):
"""Set the value of the Literal.

Attributes
Expand All @@ -77,7 +77,7 @@ def setValue(self, val):
return

value = property(
lambda self: self.getValue(), lambda self, val: self.setValue(val)
lambda self: self.getValue(), lambda self, val: self.set_value(val)
)


Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/srfit/fitbase/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def update(self):
val = self.eq()
# This will only change the Parameter if val is different from the
# currently stored value.
self.par.setValue(val)
self.par.set_value(val)
return

def _validate(self):
Expand All @@ -107,7 +107,7 @@ def _validate(self):
# Try to get the value of eq.
try:
val = self.eq()
self.par.setValue(val)
self.par.set_value(val)
except TypeError:
raise SrFitError("eq cannot be evaluated")
finally:
Expand Down
8 changes: 4 additions & 4 deletions src/diffpy/srfit/fitbase/fitrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def add_variable(
raise ValueError("The parameter '%s' is constrained" % par)
var = ParameterProxy(name, par)
if value is not None:
var.setValue(value)
var.set_value(value)
self._add_parameter(var)
if fixed:
self.fix(var)
Expand Down Expand Up @@ -1185,7 +1185,7 @@ def constrain(self, par, con, ns={}):
val = con.getValue()
if val is None:
val = par.getValue()
con.setValue(val)
con.set_value(val)

if par in self._parameters.values():
self.fix(par)
Expand Down Expand Up @@ -1352,7 +1352,7 @@ def _set_parameters_from_dict(self, params_dict):
parameter names and values."""
for param_name, param_value in params_dict.items():
if param_name in self._parameters:
self._parameters[param_name].setValue(param_value)
self._parameters[param_name].set_value(param_value)
else:
print(
f"Warning: Parameter '{param_name}' from results "
Expand Down Expand Up @@ -1742,7 +1742,7 @@ def _apply_values(self, p):
return
vargen = (v for v in self._parameters.values() if self.is_free(v))
for var, pval in zip(vargen, p):
var.setValue(pval)
var.set_value(pval)
return

def _update_configuration(self):
Expand Down
38 changes: 27 additions & 11 deletions src/diffpy/srfit/fitbase/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
from diffpy.srfit.interface import _parameter_interface
from diffpy.srfit.util.argbinders import bind2nd
from diffpy.srfit.util.nameutils import validateName
from diffpy.utils._deprecator import build_deprecation_message, deprecated

parameter_base = "diffpy.srfit.fitbase.Parameter"
removal_version = "4.0.0"
setValue_dep_msg = build_deprecation_message(
parameter_base, "setValue", "set_value", removal_version
)


class Parameter(_parameter_interface, Argument, Validatable):
Expand All @@ -46,9 +53,9 @@ class Parameter(_parameter_interface, Argument, Validatable):
const
A flag indicating whether this is considered a constant.
_value
The value of the Parameter. Modified with 'setValue'.
The value of the Parameter. Modified with 'set_value'.
value
Property for 'getValue' and 'setValue'.
Property for 'getValue' and 'set_value'.
constrained
A flag indicating if the Parameter is constrained
(default False).
Expand Down Expand Up @@ -81,7 +88,7 @@ def __init__(self, name, value=None, const=False):
Argument.__init__(self, name, value, const)
return

def setValue(self, val):
def set_value(self, val):
"""Set the value of the Parameter and the bounds.

Attributes
Expand All @@ -100,9 +107,18 @@ def setValue(self, val):
self
Returns self so that mutators can be chained.
"""
Argument.setValue(self, val)
Argument.set_value(self, val)
return self

@deprecated(setValue_dep_msg)
def setValue(self, val):
"""This function has been deprecated and will be removed in
version 4.0.0.

Please use diffpy.srfit.fitbase.Parameter.set_value instead.
"""
return self.set_value(val)

def setConst(self, const=True, value=None):
"""Toggle the Parameter as constant.

Expand All @@ -123,7 +139,7 @@ def setConst(self, const=True, value=None):
"""
self.const = bool(const)
if value is not None:
self.setValue(value)
self.set_value(value)
return self

def boundRange(self, lb=None, ub=None):
Expand Down Expand Up @@ -254,9 +270,9 @@ def _observers(self):

# wrap Parameter methods to use the target object ------------------------

@wraps(Parameter.setValue)
def setValue(self, val):
return self.par.setValue(val)
@wraps(Parameter.set_value)
def set_value(self, val):
return self.par.set_value(val)

@wraps(Parameter.getValue)
def getValue(self):
Expand Down Expand Up @@ -293,8 +309,8 @@ def _validate(self):
class ParameterAdapter(Parameter):
"""An adapter for parameter-like objects.

This class wraps an object as a Parameter. The getValue and setValue
methods defer to the data of the wrapped object.
This class wraps an object as a Parameter. The getValue and
set_value methods defer to the data of the wrapped object.
"""

def __init__(self, name, obj, getter=None, setter=None, attr=None):
Expand Down Expand Up @@ -359,7 +375,7 @@ def getValue(self):
"""Get the value of the Parameter."""
return self.getter(self.obj)

def setValue(self, value):
def set_value(self, value):
"""Set the value of the Parameter."""
if value != self.getValue():
self.setter(self.obj, value)
Expand Down
8 changes: 4 additions & 4 deletions src/diffpy/srfit/fitbase/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,19 @@ def __init__(self):
# We want x, y, ycalc and dy to stay in-sync with xpar, ypar and dypar
x = property(
lambda self: self.xpar.getValue(),
lambda self, val: self.xpar.setValue(val),
lambda self, val: self.xpar.set_value(val),
)
y = property(
lambda self: self.ypar.getValue(),
lambda self, val: self.ypar.setValue(val),
lambda self, val: self.ypar.set_value(val),
)
dy = property(
lambda self: self.dypar.getValue(),
lambda self, val: self.dypar.setValue(val),
lambda self, val: self.dypar.set_value(val),
)
ycalc = property(
lambda self: self.ycpar.getValue(),
lambda self, val: self.ycpar.setValue(val),
lambda self, val: self.ycpar.set_value(val),
)

# We want xobs, yobs and dyobs to be read-only
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srfit/interface/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ParameterInterface(object):
"""Mix-in class for enhancing the Parameter interface."""

def __lshift__(self, v):
"""SetValue with <<
"""set_value with <<

Think of '<<' as injecting a value

Expand Down
Loading
Loading