Skip to content

jsonld.expand() fails if the document contains a value which does not plainly serialize to JSON #146

@anatoly-scherbakov

Description

@anatoly-scherbakov
from pyld import jsonld
from datetime import date

jsonld.expand({'@context': {'@vocab': 'https://schema.org/'}, '@id': 'https://example.blog/post', 'publicationDate': datetime.date(2021, 1, 11)})

Which gives:

...
  File "{venv}/lib/python3.8/site-packages/pyld/jsonld.py", line 3523, in _expand_value
    if not (_is_bool(value) or _is_numeric(value) or _is_string(value)):
  File "{venv}/lib/python3.8/site-packages/pyld/jsonld.py", line 6402, in _is_numeric
    float(v)
TypeError: float() argument must be a string or a number, not 'datetime.date'
  1. Is this intended behavior? If yes, I probably could come up with a PR which would print a human understandable message instead of crash;
  2. If it is not, maybe date and datetime values should be natively supported by the library.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions