Skip to content

Commit de50055

Browse files
committed
fix: use numpy-style docstring
1 parent f51ac3e commit de50055

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2928
-1557
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Release notes
99

1010

1111
Version 3.0.0 – 2019-03-14
12-
==========================
12+
--------------------------
1313

1414
**Added:**
1515

news/fix-docstring.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: Fix the docstring in this repo
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/srfit/equation/builder.py

Lines changed: 109 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,17 @@
109109
class EquationFactory(object):
110110
"""A Factory for equations.
111111
112-
builders -- A dictionary of BaseBuilders registered with the
113-
factory, indexed by name.
114-
newargs -- A set of new arguments created by makeEquation. This is
115-
redefined whenever makeEquation is called.
116-
equations -- Set of equations that have been built by the
117-
EquationFactory.
112+
Attributes
113+
----------
114+
builders
115+
A dictionary of BaseBuilders registered with the
116+
factory, indexed by name.
117+
newargs
118+
A set of new arguments created by makeEquation. This is
119+
redefined whenever makeEquation is called.
120+
equations
121+
Set of equations that have been built by the
122+
EquationFactory.
118123
"""
119124

120125
symbols = ("+", "-", "*", "/", "**", "%", "|")
@@ -138,20 +143,25 @@ def makeEquation(
138143
"""Make an equation from an equation string.
139144
140145
Arguments
141-
eqstr -- An equation in string form using standard python
142-
syntax. The equation string can use any function
143-
registered literal or function, including numpy ufuncs
144-
that are automatically registered.
145-
buildargs -- A flag indicating whether missing arguments can be
146-
created by the Factory (default True). If False, then
147-
the a ValueError will be raised if there are undefined
148-
arguments in the eqstr. Built arguments will be of type
149-
argclass.
150-
argclass -- Class to use when creating new Arguments (default
151-
diffpy.srfit.equation.literals.Argument). The class
152-
constructor must accept the 'name' key word.
153-
argkw -- Key word dictionary to pass to the argclass constructor
154-
(default {}).
146+
---------
147+
eqstr
148+
An equation in string form using standard python
149+
syntax. The equation string can use any function
150+
registered literal or function, including numpy ufuncs
151+
that are automatically registered.
152+
buildargs
153+
A flag indicating whether missing arguments can be
154+
created by the Factory (default True). If False, then
155+
the a ValueError will be raised if there are undefined
156+
arguments in the eqstr. Built arguments will be of type
157+
argclass.
158+
argclass
159+
Class to use when creating new Arguments (default
160+
diffpy.srfit.equation.literals.Argument). The class
161+
constructor must accept the 'name' key word.
162+
argkw
163+
Key word dictionary to pass to the argclass constructor
164+
(default {}).
155165
156166
Returns a callable Literal representing the equation string.
157167
"""
@@ -202,11 +212,16 @@ def registerFunction(self, name, func, argnames):
202212
203213
This will register a builder for the function.
204214
205-
name -- The name of the function
206-
func -- A callable python object
207-
argnames-- The argument names for func. If these names do not
208-
correspond to builders, then new constants with value 0
209-
will be created for each name.
215+
Attributes
216+
----------
217+
name
218+
The name of the function
219+
func
220+
A callable python object
221+
argnames
222+
The argument names for func. If these names do not
223+
correspond to builders, then new constants with value 0
224+
will be created for each name.
210225
211226
Returns the registered builder.
212227
"""
@@ -294,16 +309,21 @@ def _prepareBuilders(self, eqstr, buildargs, argclass, argkw):
294309
rebuilds the newargs attribute.
295310
296311
Arguments
297-
eqstr -- An equation in string as specified in the makeEquation
298-
method.
299-
buildargs -- A flag indicating whether missing arguments can be
300-
created by the factory. If False, then the a ValueError
301-
will be raised if there are undefined arguments in the
302-
eqstr.
303-
argclass -- Class to use when creating new Arguments. The class
304-
constructor must accept the 'name' key word.
305-
argkw -- Key word dictionary to pass to the argclass
306-
constructor.
312+
---------
313+
eqstr
314+
An equation in string as specified in the makeEquation
315+
method.
316+
buildargs
317+
A flag indicating whether missing arguments can be
318+
created by the factory. If False, then the a ValueError
319+
will be raised if there are undefined arguments in the
320+
eqstr.
321+
argclass
322+
Class to use when creating new Arguments. The class
323+
constructor must accept the 'name' key word.
324+
argkw
325+
Key word dictionary to pass to the argclass
326+
constructor.
307327
308328
Raises ValueError if new arguments must be created, but this is
309329
disallowed due to the buildargs flag.
@@ -392,7 +412,9 @@ class BaseBuilder(object):
392412
arguments can be other BaseBuilder instances or constants.
393413
394414
Attributes
395-
literal -- The equation Literal being built by this instance.
415+
----------
416+
literal
417+
The equation Literal being built by this instance.
396418
"""
397419

398420
def __init__(self):
@@ -424,8 +446,11 @@ def __evalBinary(self, other, OperatorClass, onleft=True):
424446
425447
Other can be an BaseBuilder or a constant.
426448
427-
onleft -- Indicates that the operator was passed on the left side
428-
(default True).
449+
Attributes
450+
----------
451+
onleft
452+
Indicates that the operator was passed on the left side
453+
(default True).
429454
"""
430455
# Create the Operator
431456
op = OperatorClass()
@@ -520,20 +545,27 @@ class ArgumentBuilder(BaseBuilder):
520545
arguments can be other BaseBuilder instances or constants.
521546
522547
Attributes
523-
literal -- The Argument wrapped by this instance.
548+
----------
549+
literal
550+
The Argument wrapped by this instance.
524551
"""
525552

526553
def __init__(self, value=None, name=None, const=False, arg=None):
527554
"""Create an ArgumentBuilder instance, containing a new Argument.
528555
529556
Arguments
530-
value -- The value of the wrapped Argument (float, default None)
531-
name -- The name of the wrapped Argument (string, default None)
532-
const -- Flag indicating whether the Argument is constant (bool,
533-
default False)
534-
arg -- A pre-defined Argument to use. If this is None (default),
535-
then a new Argument will be created from value, name and
536-
const.
557+
---------
558+
value
559+
The value of the wrapped Argument (float, default None)
560+
name
561+
The name of the wrapped Argument (string, default None)
562+
const
563+
Flag indicating whether the Argument is constant (bool,
564+
default False)
565+
arg
566+
A pre-defined Argument to use. If this is None (default),
567+
then a new Argument will be created from value, name and
568+
const.
537569
"""
538570
BaseBuilder.__init__(self)
539571
if arg is None:
@@ -552,19 +584,25 @@ class OperatorBuilder(BaseBuilder):
552584
"""BaseBuilder wrapper around an Operator literal.
553585
554586
Attributes
555-
literal -- The Operator wrapped by this instance.
556-
name -- The name of the operator to be wrapped
587+
----------
588+
literal
589+
The Operator wrapped by this instance.
590+
name
591+
The name of the operator to be wrapped
557592
"""
558593

559594
def __init__(self, name, op=None):
560595
"""Wrap an Operator or a function by name.
561596
562597
Arguments
563-
name -- The name of the wrapped Operator
564-
op -- If specified, this sets the literal attribute as this
565-
operator (default None). Otherwise, the name is assumed to
566-
be that of a numpy ufunc, which is used to specify the
567-
Operator.
598+
---------
599+
name
600+
The name of the wrapped Operator
601+
op
602+
If specified, this sets the literal attribute as this
603+
operator (default None). Otherwise, the name is assumed to
604+
be that of a numpy ufunc, which is used to specify the
605+
Operator.
568606
"""
569607
BaseBuilder.__init__(self)
570608
self.name = name
@@ -576,7 +614,10 @@ def __call__(self, *args):
576614
577615
This creates a new builder that encapsulates the operation.
578616
579-
args -- Arguments of the operation.
617+
Attributes
618+
----------
619+
args
620+
Arguments of the operation.
580621
581622
Raises ValueError if self.literal.nin >= 0 and len(args) != op.nin
582623
"""
@@ -637,10 +678,16 @@ def wrapOperator(name, op):
637678
def wrapFunction(name, func, nin=2, nout=1):
638679
"""Wrap a function in an OperatorBuilder instance.
639680
640-
name -- The name of the function
641-
func -- A callable python object
642-
nin -- The number of input arguments (default 2)
643-
nout -- The number of return values (default 1)
681+
Attributes
682+
----------
683+
name
684+
The name of the function
685+
func
686+
A callable python object
687+
nin
688+
The number of input arguments (default 2)
689+
nout
690+
The number of return values (default 1)
644691
645692
Returns the OperatorBuilder instance that wraps the function.
646693
"""
@@ -661,7 +708,8 @@ def getBuilder(name):
661708

662709
def __wrapNumpyOperators():
663710
"""Export all numpy operators as OperatorBuilder instances in the module
664-
namespace."""
711+
namespace.
712+
"""
665713
for name in dir(numpy):
666714
op = getattr(numpy, name)
667715
if isinstance(op, numpy.ufunc):
@@ -676,7 +724,8 @@ def __wrapNumpyOperators():
676724
def __wrapSrFitOperators():
677725
"""Export all non-base operators from the
678726
diffpy.srfit.equation.literals.operators module as OperatorBuilder
679-
instances in the module namespace."""
727+
instances in the module namespace.
728+
"""
680729
opmod = literals.operators
681730
excluded_types = set((opmod.CustomOperator, opmod.UFuncOperator))
682731

src/diffpy/srfit/equation/equationmod.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,32 @@ class Equation(Operator):
5656
accepts new argument values for the literal tree.
5757
5858
Attributes
59-
root -- The root Literal of the equation tree
60-
argdict -- An OrderedDict of Arguments from the root.
61-
args -- Property that gets the values of argdict.
59+
----------
60+
root
61+
The root Literal of the equation tree
62+
argdict
63+
An OrderedDict of Arguments from the root.
64+
args
65+
Property that gets the values of argdict.
6266
6367
Operator Attributes
64-
args -- List of Literal arguments, set with 'addLiteral'
65-
name -- A name for this operator. e.g. "add" or "sin"
66-
nin -- Number of inputs (<1 means this is variable)
67-
nout -- Number of outputs
68-
operation -- Function that performs the operation. e.g. numpy.add.
69-
symbol -- The symbolic representation. e.g. "+" or "sin".
70-
_value -- The value of the Operator.
71-
value -- Property for 'getValue'.
68+
-------------------
69+
args
70+
List of Literal arguments, set with 'addLiteral'
71+
name
72+
A name for this operator. e.g. "add" or "sin"
73+
nin
74+
Number of inputs (<1 means this is variable)
75+
nout
76+
Number of outputs
77+
operation
78+
Function that performs the operation. e.g. numpy.add.
79+
symbol
80+
The symbolic representation. e.g. "+" or "sin".
81+
_value
82+
The value of the Operator.
83+
value
84+
Property for 'getValue'.
7285
"""
7386

7487
# define abstract attributes from the Operator base.
@@ -78,10 +91,14 @@ class Equation(Operator):
7891
def __init__(self, name=None, root=None):
7992
"""Initialize.
8093
81-
name -- A name for this Equation.
82-
root -- The root node of the Literal tree (default None). If root
83-
is not passed here, you must call the 'setRoot' method to
84-
set or change the root node.
94+
Attributes
95+
----------
96+
name
97+
A name for this Equation.
98+
root
99+
The root node of the Literal tree (default None). If root
100+
is not passed here, you must call the 'setRoot' method to
101+
set or change the root node.
85102
"""
86103
# Operator stuff. We circumvent Operator.__init__ since we're using
87104
# args as a property. We cannot set it, as the Operator tries to do.
@@ -127,7 +144,7 @@ def __getattr__(self, name):
127144
)
128145

129146
def __dir__(self):
130-
"Return sorted list of attributes for this object."
147+
"""Return sorted list of attributes for this object."""
131148
rv = set(dir(type(self)))
132149
rv.update(self.__dict__, self.argdict)
133150
rv = sorted(rv)

0 commit comments

Comments
 (0)