core/stats: get rid of duplicated keys for 'auto stats'
previously: ``` {'iter_data': {'iter_data': {'count': 9, 'last': datetime.datetime(2020, 1, 3, 1, 1, 1)}}} ``` after ``` {'iter_data': {'count': 9, 'last': datetime.datetime(2020, 1, 3, 1, 1, 1)}} ```
This commit is contained in:
parent
c5fe2e9412
commit
bf6f57c7db
3 changed files with 63 additions and 7 deletions
|
@ -401,7 +401,12 @@ C = TypeVar('C')
|
|||
Stats = Dict[str, Any]
|
||||
StatsFun = Callable[[], Stats]
|
||||
# todo not sure about return type...
|
||||
def stat(func: Union[Callable[[], Iterable[C]], Iterable[C]], quick: bool=False) -> Stats:
|
||||
def stat(
|
||||
func: Union[Callable[[], Iterable[C]], Iterable[C]],
|
||||
*,
|
||||
quick: bool = False,
|
||||
name: Optional[str] = None,
|
||||
) -> Stats:
|
||||
if callable(func):
|
||||
fr = func()
|
||||
fname = func.__name__
|
||||
|
@ -409,18 +414,20 @@ def stat(func: Union[Callable[[], Iterable[C]], Iterable[C]], quick: bool=False)
|
|||
# meh. means it's just a list.. not sure how to generate a name then
|
||||
fr = func
|
||||
fname = f'unnamed_{id(fr)}'
|
||||
tname = type(fr).__name__
|
||||
if tname == 'DataFrame':
|
||||
type_name = type(fr).__name__
|
||||
if type_name == 'DataFrame':
|
||||
# dynamic, because pandas is an optional dependency..
|
||||
df = cast(Any, fr) # todo ugh, not sure how to annotate properly
|
||||
df = cast(Any, fr) # todo ugh, not sure how to annotate properly
|
||||
res = dict(
|
||||
dtypes=df.dtypes.to_dict(),
|
||||
rows=len(df),
|
||||
)
|
||||
else:
|
||||
res = _stat_iterable(fr, quick=quick)
|
||||
|
||||
stat_name = name if name is not None else fname
|
||||
return {
|
||||
fname: res,
|
||||
stat_name: res,
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue