|
3 | 3 | # vi: set ft=python sts=4 ts=4 sw=4 et:
|
4 | 4 | """Miscellaneous utility functions
|
5 | 5 | """
|
6 |
| -from __future__ import print_function, division, unicode_literals, absolute_import |
| 6 | +from __future__ import print_function, unicode_literals, division, absolute_import |
7 | 7 | from future import standard_library
|
8 | 8 | standard_library.install_aliases()
|
9 | 9 | from builtins import next, str
|
@@ -66,47 +66,6 @@ def trim(docstring, marker=None):
|
66 | 66 | return '\n'.join(trimmed)
|
67 | 67 |
|
68 | 68 |
|
69 |
| -def getsource(function): |
70 |
| - """Returns the source code of a function""" |
71 |
| - src = dedent(inspect.getsource(function)) |
72 |
| - return src |
73 |
| - |
74 |
| - |
75 |
| -def create_function_from_source(function_source, imports=None): |
76 |
| - """Return a function object from a function source |
77 |
| -
|
78 |
| - Parameters |
79 |
| - ---------- |
80 |
| - function_source : pickled string |
81 |
| - string in pickled form defining a function |
82 |
| - imports : list of strings |
83 |
| - list of import statements in string form that allow the function |
84 |
| - to be executed in an otherwise empty namespace |
85 |
| - """ |
86 |
| - ns = {} |
87 |
| - import_keys = [] |
88 |
| - try: |
89 |
| - if imports is not None: |
90 |
| - for statement in imports: |
91 |
| - exec(statement, ns) |
92 |
| - import_keys = list(ns.keys()) |
93 |
| - exec(function_source, ns) |
94 |
| - |
95 |
| - except Exception as e: |
96 |
| - msg = '\nError executing function:\n %s\n' % function_source |
97 |
| - msg += '\n'.join(["Functions in connection strings have to be standalone.", |
98 |
| - "They cannot be declared either interactively or inside", |
99 |
| - "another function or inline in the connect string. Any", |
100 |
| - "imports should be done inside the function" |
101 |
| - ]) |
102 |
| - raise_from(RuntimeError(msg), e) |
103 |
| - ns_funcs = list(set(ns) - set(import_keys + ['__builtins__'])) |
104 |
| - assert len(ns_funcs) == 1, "Function or inputs are ill-defined" |
105 |
| - funcname = ns_funcs[0] |
106 |
| - func = ns[funcname] |
107 |
| - return func |
108 |
| - |
109 |
| - |
110 | 69 | def find_indices(condition):
|
111 | 70 | "Return the indices where ravel(condition) is true"
|
112 | 71 | res, = np.nonzero(np.ravel(condition))
|
|
0 commit comments