def new_space(self, name=None, bases=None, formula=None, refs=None): """Create a child space. Args: name (str, optional): Name of the space. Defaults to ``SpaceN``, where ``N`` is a number determined automatically. bases (optional): A space or a sequence of spaces to be the base space(s) of the created space. formula (optional): Function to specify the parameters of dynamic child spaces. The signature of this function is used for setting parameters for dynamic child spaces. This function should return a mapping of keyword arguments to be passed to this method when the dynamic child spaces are created. Returns: The new child space. """ space = self._impl.model.currentspace = self._impl.spacemgr.new_space( self._impl, name=name, bases=get_impls(bases), formula=formula, refs=refs) return space.interface
def import_module(self, module=None, recursive=False, **params): """Create a child space from an module. Args: module: a module object or name of the module object. recursive: Not yet implemented. **params: arguments to pass to ``new_space`` Returns: The new child space created from the module. """ if module is None: if "module_" in params: warnings.warn( "Parameter 'module_' is deprecated. Use 'module' instead.") module = params.pop("module_") else: raise ValueError("no module specified") if "bases" in params: params["bases"] = get_impls(params["bases"]) space = ( self._impl.model.currentspace ) = self._impl.new_space_from_module( module, recursive=recursive, **params ) return get_interfaces(space)
def to_frame(self, *args): """Convert the cells in the view into a DataFrame object. If ``args`` is not given, this method returns a DataFrame that has an Index or a MultiIndex depending of the number of cells parameters and columns each of which corresponds to each cells included in the view. ``args`` can be given to calculate cells values and limit the DataFrame indexes to the given arguments. The cells in this view may have different number of parameters, but parameters shared among multiple cells must appear in the same position in all the parameter lists. For example, Having ``foo()``, ``bar(x)`` and ``baz(x, y=1)`` is okay because the shared parameter ``x`` is always the first parameter, but this method does not work if the view has ``quz(x, z=2, y=1)`` cells in addition to the first three cells, because ``y`` appears in different positions. Args: args(optional): multiple arguments, or an iterator of arguments to the cells. """ if sys.version_info < (3, 6, 0): from collections import OrderedDict impls = OrderedDict() for name, obj in self.items(): impls[name] = obj._impl else: impls = get_impls(self) return _to_frame_inner(impls, args)
def new_space_from_module(self, module, recursive=False, **params): """Create a child space from an module. Alias to :py:meth:`import_module`. Args: module: a module object or name of the module object. recursive: Not yet implemented. **params: arguments to pass to :meth:`new_space` Returns: The new child space created from the module. """ if "bases" in params: params["bases"] = get_impls(params["bases"]) space = ( self._impl.model.currentspace) = self._impl.new_space_from_module( module, recursive=recursive, **params) return get_interfaces(space)
def get_dynspace(self, args, kwargs=None): """Create a dynamic root space Called from interface methods """ node = get_node(self, *convert_args(args, kwargs)) key = node[KEY] if key in self.param_spaces: return self.param_spaces[key] else: last_self = self.system.self self.system.self = self try: space_args = self.eval_formula(node) finally: self.system.self = last_self if space_args is None: space_args = {"bases": [self]} # Default else: if "bases" in space_args: bases = get_impls(space_args["bases"]) if isinstance(bases, StaticSpaceImpl): space_args["bases"] = [bases] elif bases is None: space_args["bases"] = [self] # Default else: space_args["bases"] = bases else: space_args["bases"] = [self] space_args["arguments"] = node_get_args(node) space = self._new_dynspace(**space_args) self.param_spaces[key] = space space.inherit(clear_value=False) return space
def add_bases(self, *bases): """Add base spaces.""" return self._impl.add_bases(get_impls(bases))
def remove_bases(self, bases): # bases are interfaces for base in get_impls(bases): self.remove_base(base)