Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Computation abstract class #30

Closed
khaeru opened this issue Feb 16, 2021 · 0 comments · Fixed by #98
Closed

Add a Computation abstract class #30

khaeru opened this issue Feb 16, 2021 · 0 comments · Fixed by #98
Assignees
Labels
enh New feature or request

Comments

@khaeru
Copy link
Owner

khaeru commented Feb 16, 2021

This can be the location for:

  • add_task(c: Computer) or similar for describing computations in c.
  • __call__(): the actual callable to be executed.
  • __repr__(): a more readable string representation for Computer.describe().
  • etc.

These should be easier to maintain if they are collected, instead of the separate pair of e.g. Computer.convert_pyam (for adding task(s)) and .compat.pyam.computations.as_pyam (the actual callable)

This will also alow to reduce complexity of this code in Computer.add():

elif isinstance(data, str) and self.get_comp(data):
# *data* is the name of a pre-defined computation
name = data
if hasattr(self, f"add_{name}"):
# Use a method on the current class to add. This invokes any
# argument-handling conveniences, e.g. Computer.add_product()
# instead of using the bare product() computation directly.
return getattr(self, f"add_{name}")(*args, **kwargs)
else:
# Get the function directly
func = self.get_comp(name)
# Rearrange arguments: key, computation function, args, …
func, kwargs = partial_split(func, kwargs)
return self.add(args[0], func, *args[1:], **kwargs)
elif isinstance(data, str) and data in dir(self):
# Name of another method, e.g. 'apply'
return getattr(self, data)(*args, **kwargs)

The Computer can:

  • Look up the Computation class in Computer.modules.
  • If it has an add_task() method, call that directly; else, simply instantiate.
@khaeru khaeru added the enh New feature or request label Feb 16, 2021
khaeru added a commit that referenced this issue Feb 16, 2021
In the future, add_aggregate() should be preferred, so that Computer
method names do not too closely imitate computation function names.
See also #30.
@khaeru khaeru self-assigned this May 11, 2021
@khaeru khaeru linked a pull request Aug 18, 2023 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enh New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant