diff --git a/tests/utils/test_sharedoc.py b/tests/utils/test_sharedoc.py new file mode 100644 index 00000000..bed1cef9 --- /dev/null +++ b/tests/utils/test_sharedoc.py @@ -0,0 +1,21 @@ +from zipline.testing import ZiplineTestCase +from zipline.utils.sharedoc import copydoc + + +class TestSharedoc(ZiplineTestCase): + + def test_copydoc(self): + def original_docstring_function(): + """ + My docstring brings the boys to the yard. + """ + pass + + @copydoc(original_docstring_function) + def copied_docstring_function(): + pass + + self.assertEqual( + original_docstring_function.__doc__, + copied_docstring_function.__doc__ + ) diff --git a/zipline/pipeline/engine.py b/zipline/pipeline/engine.py index 65a8a6ab..00906f90 100644 --- a/zipline/pipeline/engine.py +++ b/zipline/pipeline/engine.py @@ -12,7 +12,6 @@ from six import ( with_metaclass, ) from numpy import array -from odo.utils import copydoc from pandas import DataFrame, MultiIndex from toolz import groupby, juxt from toolz.curried.operator import getitem @@ -30,6 +29,7 @@ from .term import AssetExists, InputDates, LoadableTerm from zipline.utils.date_utils import compute_date_range_chunks from zipline.utils.pandas_utils import categorical_df_concat +from zipline.utils.sharedoc import copydoc class PipelineEngine(with_metaclass(ABCMeta)): diff --git a/zipline/utils/sharedoc.py b/zipline/utils/sharedoc.py index d0d7248c..6ba53607 100644 --- a/zipline/utils/sharedoc.py +++ b/zipline/utils/sharedoc.py @@ -5,6 +5,7 @@ across different functions. import re from six import iteritems from textwrap import dedent +from toolz import curry PIPELINE_DOWNSAMPLING_FREQUENCY_DOC = dedent( """\ @@ -98,3 +99,21 @@ def templated_docstring(**docs): f.__doc__ = format_docstring(f.__name__, f.__doc__, docs) return f return decorator + + +@curry +def copydoc(from_, to): + """Copies the docstring from one function to another. + Parameters + ---------- + from_ : any + The object to copy the docstring from. + to : any + The object to copy the docstring to. + Returns + ------- + to : any + ``to`` with the docstring from ``from_`` + """ + to.__doc__ = from_.__doc__ + return to