Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pd.DataFrame breaks JSON schema generation #28

Closed
thomas-pedot opened this issue Jul 21, 2021 · 3 comments
Closed

pd.DataFrame breaks JSON schema generation #28

thomas-pedot opened this issue Jul 21, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@thomas-pedot
Copy link

thomas-pedot commented Jul 21, 2021

When using Arbitrary type we cannot serialize to a JSON Schema.

Work

PandasDataFrame = TypeVar('pd.DataFrame')

class Model(BaseModel):
    pandasDF:  PandasDataFrame 

Doesnot work

class Model(BaseModel):
    pandasDF:  pd.DataFrame
    class Config:
        arbitrary_types_allowed = True # pd.DataFrame allowed

Following error is raised when building the docs:

ValueError: Value not declarable with JSON Schema, field: name='inputs_DataFrame' type=DataFrame required=True

@mansenfranzen
Copy link
Owner

Thanks for the bug report. I can reproduce the issue. Be aware there is already a mechanism to capture fields which are not JSON serializable (see warning here in the docs). However, the pandas dataframe dtype currently escapes this safety guard.

@mansenfranzen mansenfranzen self-assigned this Jul 23, 2021
@mansenfranzen mansenfranzen added the bug Something isn't working label Jul 23, 2021
@mansenfranzen mansenfranzen changed the title ValueError: Value not declarable with JSON Schema, field: name='inputs_DataFrame' type=DataFrame required=True pd.DataFrame breaks JSON schema generation Jul 23, 2021
@mansenfranzen mansenfranzen changed the title pd.DataFrame breaks JSON schema generation pd.DataFrame breaks JSON schema generation Jul 23, 2021
@mansenfranzen
Copy link
Owner

@thomas-pedot PR #30 addresses the current issue allowing you to define how autodoc_pydantic should behave in case a pydantic field can't be JSON serialized properly. Please see the updated docs on this.

Before merging the related PR, it would be great if you could test the bug fix on your site to confirm that my test case did indeed capture the incorrect behavior which you've encountered. To do so, please install the current dev release in your doc-building-environment via pip install git+git://github.com/mansenfranzen/[email protected] and rebuild your docs.

mansenfranzen added a commit that referenced this issue Jul 30, 2021
…a#28

Bug fix json schema #28 (Sourcery refactored)
mansenfranzen added a commit that referenced this issue Aug 18, 2021
@mansenfranzen
Copy link
Owner

Closing this issue via #30. Please feel free to reopen for further discussions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants