pandera icon indicating copy to clipboard operation
pandera copied to clipboard

GeoPandas type not compatible with FastApi

Open mangecoeur opened this issue 2 years ago • 2 comments
trafficstars

Describe the bug A clear and concise description of what the bug is.

  • [ x] I have checked that this issue has not already been reported.
  • [ x] I have confirmed this bug exists on the latest version of pandera.
  • [ ] (optional) I have confirmed this bug exists on the master branch of pandera.

Code Sample, a copy-pastable example

import pandera as pa
from pandera.typing.geopandas import GeoDataFrame, GeoSeries
from fastapi import FastAPI


class Location(pa.SchemaModel):
    id: pa.typing.Series[int]
    point: GeoSeries

app = FastAPI()

@app.post("/", response_model=GeoDataFrame[Location])
def get_location(id: int):
    return None

Produces the error:

Fields of type "<class 'pandera.typing.geopandas.GeoDataFrame'>" are not supported.

Irrespective of whether to_format is defined.

Expected behavior

Similar to DataFrame can be used in annotation, would like to be able to use a GeoDataFrame. Conversion of the GeoDataFrame would be controlled by to_format (e.g. to produce a GeoJson). I assume that since FastAPI doesn't support DataFrame by default either somewhere the pandera types are registered with FastAPI.

Desktop (please complete the following information):

  • OS: Macos
  • Browser Firefox

mangecoeur avatar Mar 10 '23 10:03 mangecoeur

Hi @mangecoeur, relabelling this as an enhancement, as FastAPI support is only currently for pandera.typing.pandas.DataFrame (should probably document this if it isn't already)

Basically the GeoDataFrame generic class needs a get_validators method where currently it's just a bare generic class: https://github.com/unionai-oss/pandera/blob/main/pandera/typing/geopandas.py#L34

Probably won't get to this for a few months, but would welcome a PR from you or the community!

cosmicBboy avatar Mar 10 '23 15:03 cosmicBboy

I picked this up and will submit PR soon

derinwalters avatar Oct 21 '23 16:10 derinwalters