Skip to content

Commit

Permalink
Add additional documentation to ConfigurableAcations
Browse files Browse the repository at this point in the history
  • Loading branch information
natelust committed Mar 16, 2022
1 parent 7fce098 commit c1464f6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def __set__(self, instance, value, at=None, label="assignment"):

def save(self, outfile, instance):
# docstring inherited from parent
# This is different that the parent class in that this field must
# serialize which config class is assigned to this field prior to
# serializing any assignments to that config class's fields.
value = self.__get__(instance)
fullname = _joinNamePath(instance._name, self.name)
outfile.write(f"{fullname}={_typeStr(value)}\n")
Expand Down
32 changes: 32 additions & 0 deletions python/lsst/pipe/tasks/dataFrameActions/_evalColumnExpression.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,38 @@ def makeColumnExpressionAction(className: str, expr: str,
Type[DataFrameAction]]]] = None,
docstring: str = None
) -> Type[DataFrameAction]:
"""Factory function for producing ConfigurableAction classes which are
realizations of arithmetic operations.
Parameters
----------
className : `str`
The name of the class that will be produced
expr : `str`
An arithmetic expression that will be parsed to produce the output
ConfigurableAction. Individual variable names will be the name of
individual `ConfigActions` inside the expression (i.e. "x+y" will
produce an action with configAction.actions.x and
configAction.actions.y). Expression can contain arithmatic python
operators as well as; sin, cos, sinh, cosh, log (which is base 10).
exprDefaults : `Mapping` of `str` to `DataFrameAction` optional
A mapping of strings which correspond to the names in the expression to
values which are default `ConfigurableActions` to assign in the
expression. If no default for a action is supplied `SingleColumnAction`
is set as the default.
docstring : `str`
A string that is assigned as the resulting classes docstring
Returns
-------
action : `Type` of `DataFrameAction`
A `DataFrameAction` class that was programatically constructed from the
input expression.
"""
# inspect is used because this is a factory function used to produce classes
# and it is desireable that the classes generated appear to be in the
# module of the calling frame, instead of something defined within the
# scope of this function call.
import inspect
new_module = inspect.stack()[1].frame.f_locals['__name__']
node = ast.parse(expr, mode='eval')
Expand Down

0 comments on commit c1464f6

Please sign in to comment.