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

Bug fix while ordering optional keys from schema in static method from_records from pandera df #1238

Merged
merged 2 commits into from
Jun 29, 2023

Conversation

manel-ab
Copy link
Contributor

I saw a bug on from_records static method from pandera DataFrame when trying to sort columns that may be not required in the schema but are trying to be sorted:

from typing import Optional
from pandera import Field, SchemaModel
from pandera.typing import Series, DataFrame
class Schema(SchemaModel):
    state: Series[str]
    city: Series[str]
    price: Series[float]
    postal_code: Optional[Series[int]] = Field(nullable=True)

raw_data = [
    {
        "state": "NY",
        "city": "New York",
        "price": 8.0,
    },
    {
        "state": "FL",
        "city": "Miami",
        "price": 12.0,
    },
]
DataFrame.from_records(Schema, raw_data)

and raises the following error: KeyError: "['postal_code'] not in index".
Also, as is currently implemented, the keys may not be sorted as schema says.

@codecov
Copy link

codecov bot commented Jun 26, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (deaddfb) 97.25% compared to head (904a2dd) 97.25%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1238   +/-   ##
=======================================
  Coverage   97.25%   97.25%           
=======================================
  Files          65       65           
  Lines        5101     5107    +6     
=======================================
+ Hits         4961     4967    +6     
  Misses        140      140           
Impacted Files Coverage Δ
pandera/typing/pandas.py 95.50% <100.00%> (+0.05%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@manel-ab manel-ab changed the title Bug fix from_records static method from pandera df Bug fix while ordering optional keys from schema in static method from_records from pandera df Jun 26, 2023
@cosmicBboy
Copy link
Collaborator

thanks @manel-ab !

@cosmicBboy cosmicBboy merged commit dc4d8d8 into unionai-oss:main Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants