core: helpers for automatic dataframes from sequences of NamedTuple/dataclass
also use in my.rescuetime
This commit is contained in:
parent
df9a7f7390
commit
07f901e1e5
5 changed files with 77 additions and 14 deletions
|
@ -458,3 +458,16 @@ def guess_datetime(x: Any) -> Optional[datetime]:
|
|||
if isinstance(v, datetime):
|
||||
return v
|
||||
return None
|
||||
|
||||
|
||||
def asdict(thing) -> Json:
|
||||
# todo primitive?
|
||||
# todo exception?
|
||||
if isinstance(thing, dict):
|
||||
return thing
|
||||
import dataclasses as D
|
||||
if D.is_dataclass(thing):
|
||||
return D.asdict(thing)
|
||||
# must be a NT otherwise?
|
||||
# todo add a proper check.. ()
|
||||
return thing._asdict()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue