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

A helper for eval expressions on ports #64

Open
jonathanjfshaw opened this issue Apr 24, 2020 · 0 comments
Open

A helper for eval expressions on ports #64

jonathanjfshaw opened this issue Apr 24, 2020 · 0 comments

Comments

@jonathanjfshaw
Copy link
Contributor

I'm about to PR a node in timeflux_dsp that uses arbitrary rules to classify data. The rules are eval'd as expressions using ports, in the way the Expression node does.

This eval logic from Expression seems like it might be useful in quite a few contexts. It's something like this:

    def _eval_expression(self, expression):
        ports = [port_name for port_name, _, _
                                in self.iterate('i_*')
                                if port_name in expression]
        _local_dict = {port_name: self.ports.get(port_name).data
                       for port_name in ports}
        if np.any([data is None for data in _local_dict.values()]):
            return
        calculated = pd.eval(expr=expression,
                              local_dict=_local_dict,
                              **self._kwargs)
        for port_name in ports:
            self.o.meta.update(self.ports.get(port_name).meta)
        return calculated

Should it be a helper in helpers/ports.py, or should the Expression node be refactored so that other nodes can extend it more easily and inherit this method from it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant