my.core.serialize: implement default flag

Lots of surrounding changes from this discussion:
0593c69056

renamed/split error_to_json into error_to_row, moved
pandas-aware functions to my.core.pandas, leaving
generic ones in my.core.error.
This commit is contained in:
Sean Breckenridge 2021-03-18 03:04:49 -07:00
parent 0593c69056
commit c3f3650bcc
7 changed files with 172 additions and 36 deletions

View file

@ -532,7 +532,7 @@ def test_guess_datetime() -> None:
def is_namedtuple(thing: Any) -> bool:
# basic check to see if this is a namedtuple-like
# basic check to see if this is namedtuple-like
_asdict = getattr(thing, '_asdict', None)
return _asdict and callable(_asdict)
@ -550,14 +550,6 @@ def asdict(thing: Any) -> Json:
raise TypeError(f'Could not convert object {thing} to dict')
# todo not sure about naming
def to_jsons(it) -> Iterable[Json]:
from .error import error_to_json # prevent circular import
for r in it:
if isinstance(r, Exception):
yield error_to_json(r)
else:
yield asdict(r)
datetime_naive = datetime