# AUTOGENERATED! DO NOT EDIT! File to edit: 98_utils.ipynb (unless otherwise specified).

__all__ = ['delegates', 'dummy_df']

# Internal Cell

from hypothesis import given, strategies as st
import pandas as pd

# Cell
import inspect

def delegates(to=None, keep=False):
    "Decorator: replace `**kwargs` in signature with params from `to`"

    def _f(f):
        if to is None:
            to_f,from_f = f.__base__.__init__,f.__init__
        else:
            to_f,from_f = to,f

        sig = inspect.signature(from_f)
        sigd = dict(sig.parameters)
        k = sigd.pop('kwargs')
        s2 = {k:v for k,v in inspect.signature(to_f).parameters.items()
              if v.default != inspect.Parameter.empty and k not in sigd}
        sigd.update(s2)
        if keep:
            sigd['kwargs'] = k
        from_f.__doc__ = f"""
        doc string from my delegate: `{to_f.__name__}`
        --------
        {to_f.__doc__}
        """
        from_f.__signature__ = sig.replace(parameters=sigd.values())
        return f
    return _f

# Cell

def dummy_df(Model):
    instances = []
    @given(st.builds(Model))
    def test_property(instance):
        instances.append(instance.dict())
    test_property()
    return pd.DataFrame.from_records(instances)