/
wrapped.py
66 lines (52 loc) · 1.51 KB
/
wrapped.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
#
# Taylor G Smith <taylor.smith@alkaline.ml>
#
# Wrapped functions
from statsmodels.tsa.stattools import acf as sm_acf, pacf as sm_pacf
from functools import wraps
__all__ = [
'acf',
'pacf'
]
# TODO: remove all explicit args/kwargs, making them *args, **kwargs
def inheritdoc(parent):
"""Inherit documentation from a parent
Parameters
----------
parent : callable
The parent function or class that contains the sought-after
docstring. If it doesn't have a docstring, this might behave
in unexpected ways.
Examples
--------
>>> def a(x=1):
... '''This is documentation'''
... return x
...
>>> @inheritdoc(a)
... def b(x):
... return 2 * a(x)
...
>>> print(b.__doc__)
This is documentation
>>> print(b(2))
4
"""
def wrapper(func):
# Assign the parent docstring to the child
func.__doc__ = parent.__doc__
@wraps(func)
def caller(*args, **kwargs):
return func(*args, **kwargs)
return caller
return wrapper
@inheritdoc(parent=sm_acf)
def acf(x, unbiased=False, nlags=40, qstat=False, fft=False,
alpha=None, missing='none'):
return sm_acf(x=x, unbiased=unbiased, nlags=nlags,
qstat=qstat, fft=fft, alpha=alpha,
missing=missing)
@inheritdoc(parent=sm_pacf)
def pacf(x, nlags=40, method='ywunbiased', alpha=None):
return sm_pacf(x=x, nlags=nlags, method=method, alpha=alpha)