Exemplo n.º 1
0
def test_replace_block():
    ds = Docstring(good)
    ds.replace_block('summary', ['The is the new summary.'])
    assert 'The is the new summary.' in str(ds)

    ds = Docstring(good)
    ds.replace_block('summary', 'The is the new summary.')
    assert 'The is the new summary.' in str(ds)

    with pytest.raises(ValueError):
        ds.replace_block('unknown', ['The is the new summary.'])
Exemplo n.º 2
0
def test_empty_ds():
    ds = Docstring(None)
    ds.replace_block('summary', ['The is the new summary.'])

    ds.remove_parameters('x')

    new = Parameter('w', 'ndarray', ['An array input.'])
    ds.insert_parameters('y', new)
    assert str(ds) == 'None'
Exemplo n.º 3
0
def test_remove_parameter():
    ds = Docstring(good)
    ds.remove_parameters('x')
    assert 'x : int' not in str(ds)

    ds = Docstring(good)
    ds.remove_parameters(['x', 'y'])
    assert 'x : int' not in str(ds)
    assert 'y : float' not in str(ds)

    with pytest.raises(ValueError):
        Docstring(good).remove_parameters(['w'])

    ds = remove_parameters(good, 'x')
    assert 'x : int' not in ds
    assert isinstance(ds, str)
Exemplo n.º 4
0
from typing import Any, Dict, Optional, Union

import numpy as np
import pandas as pd

from statsmodels.base.data import PandasData
from statsmodels.iolib.summary import SimpleTable, Summary
from statsmodels.tools.docstring import Docstring, Parameter, indent
from statsmodels.tsa.base.prediction import PredictionResults
from statsmodels.tsa.base.tsa_model import get_index_loc, get_prediction_index
from statsmodels.tsa.seasonal import STL, DecomposeResult
from statsmodels.tsa.statespace.kalman_filter import _check_dynamic

DateLike = Union[int, str, dt.datetime, pd.Timestamp, np.datetime64]

ds = Docstring(STL.__doc__)
ds.insert_parameters(
    "endog",
    Parameter(
        "model",
        "Model",
        [
            "The model used to forecast endog after the seasonality has been "
            "removed using STL"
        ],
    ),
)
ds.insert_parameters(
    "model",
    Parameter(
        "model_kwargs",
Exemplo n.º 5
0
def test_multiple_sig():
    Docstring(with_sig)
Exemplo n.º 6
0
def test_yield_return():
    with pytest.raises(ValueError):
        Docstring(bad_yields)
Exemplo n.º 7
0
def test_bad():
    with pytest.raises(ValueError):
        Docstring(bad)
Exemplo n.º 8
0
def test_repeat():
    with pytest.raises(ValueError):
        Docstring(repeat)
Exemplo n.º 9
0
def test_set_unknown():
    ds = Docstring(good)
    with pytest.raises(ValueError):
        ds._ds['Unknown'] = ['unknown']
Exemplo n.º 10
0
def test_insert_parameters():
    new = Parameter('w', 'ndarray', ['An array input.'])
    ds = Docstring(good)
    ds.insert_parameters('y', new)
    assert 'w : ndarray' in str(ds)
    assert 'An array input.' in str(ds)

    other = Parameter('q', 'DataFrame', ['A pandas dataframe.'])
    ds = Docstring(good)
    ds.insert_parameters(None, [new, other])
    assert 'w : ndarray' in str(ds)
    assert 'An array input.' in str(ds)
    assert 'q : DataFrame' in str(ds)
    assert 'A pandas dataframe.' in str(ds)
    assert '---\nw : ndarray' in str(ds)

    ds = Docstring(good)
    with pytest.raises(ValueError):
        ds.insert_parameters('unknown', new)
Exemplo n.º 11
0
        quot = []
        rem = num
    else:
        if n is None:
            n = N - D + 1
        input = np.zeros(n, float)
        input[0] = 1
        quot = signal.lfilter(num, den, input)
        num_approx = signal.convolve(den, quot, mode="full")
        if len(num) < len(num_approx):  # 1d only ?
            num = np.concatenate((num, np.zeros(len(num_approx) - len(num))))
        rem = num - num_approx
    return quot, rem


_generate_sample_doc = Docstring(arma_generate_sample.__doc__)
_generate_sample_doc.remove_parameters(["ar", "ma"])
_generate_sample_doc.replace_block("Notes", [])
_generate_sample_doc.replace_block("Examples", [])


class ArmaProcess(object):
    r"""
    Theoretical properties of an ARMA process for specified lag-polynomials.

    Parameters
    ----------
    ar : array_like
        Coefficient for autoregressive lag polynomial, including zero lag.
        Must be entered using the signs from the lag polynomial representation.
        See the notes for more information about the sign.
Exemplo n.º 12
0
            return f"{v:0.4g}"

        return SimpleTable(
            data,
            header=cols,
            stubs=stubs,
            title="Descriptive Statistics",
            txt_fmt={"data_fmts": {0: "%s", 1: _formatter}},
            datatypes=[1] * len(data),
        )

    def __str__(self) -> str:
        return str(self.summary().as_text())


ds = Docstring(Description.__doc__)
ds.replace_block(
    "Returns", Parameter(None, "DataFrame", ["Descriptive statistics"])
)
ds.replace_block("Attributes", [])
ds.replace_block(
    "See Also",
    [
        (
            [("pandas.DataFrame.describe", None)],
            ["Basic descriptive statistics"],
        ),
        (
            [("Description", None)],
            ["Descriptive statistics class with additional output options"],
        ),
Exemplo n.º 13
0
        quot = []
        rem = num
    else:
        if n is None:
            n = N - D + 1
        input = np.zeros(n, float)
        input[0] = 1
        quot = signal.lfilter(num, den, input)
        num_approx = signal.convolve(den, quot, mode='full')
        if len(num) < len(num_approx):  # 1d only ?
            num = np.concatenate((num, np.zeros(len(num_approx) - len(num))))
        rem = num - num_approx
    return quot, rem


_generate_sample_doc = Docstring(arma_generate_sample.__doc__)
_generate_sample_doc.remove_parameters(['ar', 'ma'])
_generate_sample_doc.replace_block('Notes', [])
_generate_sample_doc.replace_block('Examples', [])


class ArmaProcess(object):
    r"""
    Theoretical properties of an ARMA process for specified lag-polynomials.

    Parameters
    ----------
    ar : array_like
        Coefficient for autoregressive lag polynomial, including zero lag.
        See the notes for some information about the sign.
    ma : array_like