diff options
author | seberg <sebastian@sipsolutions.net> | 2013-11-20 12:29:22 -0800 |
---|---|---|
committer | seberg <sebastian@sipsolutions.net> | 2013-11-20 12:29:22 -0800 |
commit | 78e29a323316642899f8ff85e538b785f0d5e31f (patch) | |
tree | fb197f0ea8f205721aa9590d9f0eafffad6aae9c /numpy/lib | |
parent | 9f611dec1ebed4c8c933d5d310ceaf67aedbb8a4 (diff) | |
parent | 66174b8aa5644b11054b72761e89e22fd8a18eae (diff) | |
download | numpy-78e29a323316642899f8ff85e538b785f0d5e31f.tar.gz |
Merge pull request #4064 from juliantaylor/import-speed
ENH: improve add_newdocs performance
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/function_base.py | 9 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 10 |
2 files changed, 14 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index a70f74f60..9176d9950 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3110,15 +3110,14 @@ def add_newdoc(place, obj, doc): that the docstrings were changed. """ try: - new = {} - exec('from %s import %s' % (place, obj), new) + new = getattr(__import__(place, globals(), {}, [obj]), obj) if isinstance(doc, str): - add_docstring(new[obj], doc.strip()) + add_docstring(new, doc.strip()) elif isinstance(doc, tuple): - add_docstring(getattr(new[obj], doc[0]), doc[1].strip()) + add_docstring(getattr(new, doc[0]), doc[1].strip()) elif isinstance(doc, list): for val in doc: - add_docstring(getattr(new[obj], val[0]), val[1].strip()) + add_docstring(getattr(new, val[0]), val[1].strip()) except: pass diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index f91ab8aa1..6829e06ae 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1808,6 +1808,7 @@ class TestMedian(TestCase): a = MySubClass([1,2,3]) assert_equal(np.median(a), -7) + class TestAdd_newdoc_ufunc(TestCase): def test_ufunc_arg(self): @@ -1818,5 +1819,14 @@ class TestAdd_newdoc_ufunc(TestCase): assert_raises(TypeError, add_newdoc_ufunc, np.add, 3) +class TestAdd_newdoc(TestCase): + def test_add_doc(self): + # test np.add_newdoc + tgt = "Current flat index into the array." + self.assertEqual(np.core.flatiter.index.__doc__[:len(tgt)], tgt) + self.assertTrue(len(np.core.ufunc.identity.__doc__) > 300) + self.assertTrue(len(np.lib.index_tricks.mgrid.__doc__) > 300) + + if __name__ == "__main__": run_module_suite() |