Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/diffpy/srfit/equation/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def __wrapSrFitOperators():
opmod = literals.operators
excluded_types = set((opmod.CustomOperator, opmod.UFuncOperator))
# check if opmod member should be wrapped as OperatorBuilder
is_exported_type = lambda cls: (
is_exported_type = lambda cls: ( # noqa: E731

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find this very readable. We can't do better here?

inspect.isclass(cls)
and issubclass(cls, opmod.Operator)
and not inspect.isabstract(cls)
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srfit/fitbase/fithook.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def postcall(self, recipe, chiv):
print("Variables")
vnames = recipe.getNames()
vals = recipe.getValues()
byname = lambda nv: sortKeyForNumericString(nv[0])
byname = lambda nv: sortKeyForNumericString(nv[0]) # noqa: E731
Comment thread
bobleesj marked this conversation as resolved.
Resolved
items = sorted(zip(vnames, vals), key=byname)
for name, val in items:
print(" %s = %f" % (name, val))
Expand Down
10 changes: 5 additions & 5 deletions src/diffpy/srfit/fitbase/recipeorganizer.py
Comment thread
bobleesj marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def clearConstraints(self, recurse=False):
self.unconstrain(*self._constraints)

if recurse:
f = lambda m: hasattr(m, "clearConstraints")
f = lambda m: hasattr(m, "clearConstraints") # noqa: E731
Comment thread
bobleesj marked this conversation as resolved.
Resolved
for m in filter(f, self._iterManaged()):
m.clearConstraints(recurse)
return
Expand Down Expand Up @@ -813,7 +813,7 @@ def clearRestraints(self, recurse=False):
self.unrestrain(*self._restraints)

if recurse:
f = lambda m: hasattr(m, "clearRestraints")
f = lambda m: hasattr(m, "clearRestraints") # noqa: E731
Comment thread
bobleesj marked this conversation as resolved.
Resolved
for m in filter(f, self._iterManaged()):
m.clearRestraints(recurse)
return
Expand All @@ -822,7 +822,7 @@ def _getConstraints(self, recurse=True):
"""Get the constrained Parameters for this and managed sub-objects."""
constraints = {}
if recurse:
f = lambda m: hasattr(m, "_getConstraints")
f = lambda m: hasattr(m, "_getConstraints") # noqa: E731
for m in filter(f, self._iterManaged()):
constraints.update(m._getConstraints(recurse))

Expand All @@ -837,7 +837,7 @@ def _getRestraints(self, recurse=True):
"""
restraints = set(self._restraints)
if recurse:
f = lambda m: hasattr(m, "_getRestraints")
f = lambda m: hasattr(m, "_getRestraints") # noqa: E731
for m in filter(f, self._iterManaged()):
restraints.update(m._getRestraints(recurse))

Expand Down Expand Up @@ -948,7 +948,7 @@ def show(self, pattern="", textwidth=78):
the screen width. Do not trim when negative or 0.
"""
regexp = re.compile(pattern)
pmatch = lambda s: (len(s.split(None, 1)) < 2 or regexp.search(s.split(None, 1)[0]))
pmatch = lambda s: (len(s.split(None, 1)) < 2 or regexp.search(s.split(None, 1)[0])) # noqa: E731
Comment thread
bobleesj marked this conversation as resolved.
Resolved
# Show sub objects and their parameters
lines = []
tlines = self._formatManaged()
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srfit/pdf/characteristicfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def lognormalSphericalCF(r, psize, psig):
if psig <= 0:
return sphericalCF(r, psize)

erfc = lambda x: 1.0 - erf(x)
erfc = lambda x: 1.0 - erf(x) # noqa: E731
Comment thread
bobleesj marked this conversation as resolved.
Resolved

sqrt2 = sqrt(2.0)
s = sqrt(log(psig * psig / (1.0 * psize * psize) + 1))
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srfit/sas/prcalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __call__(self, r):
self._invertor.y = iq
self._invertor.err = diq
c, c_cov = self._invertor.invert_optimize()
calculate_pr = lambda x: self._invertor.pr(c, x)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using lambda functions that are short and concise actually increase readability... Hence adding # noqa: E731 as well.

calculate_pr = lambda x: self._invertor.pr(c, x) # noqa: E731

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one also better to put it in the map directly? Or maybe as an explicit function

pr = map(calculate_pr, r)

pr = numpy.array(pr)
Expand Down
6 changes: 3 additions & 3 deletions src/diffpy/srfit/tests/testbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def testParseEquation(self):
eq.x.setValue(x)
eq.B.setValue(B)
eq.C.setValue(C)
f = lambda A, x, B, C: A * sin(0.5 * x) + divide(B, C)
f = lambda A, x, B, C: A * sin(0.5 * x) + divide(B, C) # noqa: E731
self.assertTrue(array_equal(eq(), f(A, x, B, C)))

# Make sure that the arguments of eq are listed in the order in which
Expand All @@ -170,7 +170,7 @@ def testParseEquation(self):
sigma = 0.1
eq.x.setValue(x)
eq.sigma.setValue(sigma)
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2))
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2)) # noqa: E731

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here in the tests they are quite readable and not doing much harm so I suggest leaving with noqa

self.assertTrue(numpy.allclose(eq(), f(x, sigma)))

self.assertEqual(eq.args, [eq.x, eq.sigma])
Expand Down Expand Up @@ -246,7 +246,7 @@ def _f(a, b):
sigma = builder.ArgumentBuilder(name="sigma", value=0.1)
beq = sqrt(e ** (-0.5 * (x / sigma) ** 2))
eq = beq.getEquation()
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2))
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2)) # noqa: E731
self.assertTrue(numpy.allclose(eq(), numpy.sqrt(e ** (-0.5 * (_x / 0.1) ** 2))))

# Equation with Equation
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srfit/tests/testcontribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_releaseOldEquations(self):
def test_registerFunction(self):
"""Ensure registered function works after second setEquation call."""
fc = self.fitcontribution
fsquare = lambda x: x**2
fsquare = lambda x: x**2 # noqa: E731
fc.registerFunction(fsquare, name="fsquare")
fc.setEquation("fsquare")
fc.x.setValue(5)
Expand Down