Giter Site home page Giter Site logo

Comments (7)

cosmicBboy avatar cosmicBboy commented on June 5, 2024

This looks like a duplicate of #1395, correct?

from pandera.

tkaraouzene avatar tkaraouzene commented on June 5, 2024

My bad I forgot to specify that I was using pydantic v1 (1.10.2). So no it is not a duplicate

from pandera.

cosmicBboy avatar cosmicBboy commented on June 5, 2024

Gotcha. Feel free to try and debug this and opening a PR for a fix!

The part of the codebase that creates the json schema representation is here

from pandera.

tkaraouzene avatar tkaraouzene commented on June 5, 2024

Thanks, I'll have a look on it

from pandera.

eharkins avatar eharkins commented on June 5, 2024

@tkaraouzene did you have any success getting pandera to work with generating openapi schema accurately using pydantic v1 and fastapi? I am having a similar issue where I am orienting the dataframe as records (list) but openapi is generating a schema where each column is an array like:

                 "year_id": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    }
                  },

My actual response model is returned as a list of record objects that each have a year_id, etc. , which doesn't match the schema being generated.

from pandera.

cosmicBboy avatar cosmicBboy commented on June 5, 2024

The state of the json_schema support is still the same as before, see this issue: #1395

Would welcome any PRs to actually fix the to_json_schema function here:

def _to_json_schema(dataframe_schema):
"""Serialize schema metadata into json-schema format.
:param dataframe_schema: schema to write to json-schema format.
.. note::
This function is currently does not fully specify a pandera schema,
and is primarily used internally to render OpenAPI docs via the
FastAPI integration.
"""

from pandera.

eharkins avatar eharkins commented on June 5, 2024

Ok, thanks. In the meantime is there a recommended way to override the _to_json_schema function to explicitly specify the schema? Alternatively, would returning a dataframe model with

    class Config:
        to_format = "dict"
        to_format_kwargs = {"orient": "list"}

match the way that the schema is currently generated with columns as arrays?

Edit: using the above kwargs worked for me to make my responses match the way pandera generates the openapi schema

from pandera.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.