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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandera/typing/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def from_records( # type: ignore
schema_index = schema.index.names if schema.index is not None else None
if "index" not in kwargs:
kwargs["index"] = schema_index
data_df = pd.DataFrame.from_records(data=data, **kwargs)
return DataFrame[schema]( # type: ignore
pd.DataFrame.from_records(data=data, **kwargs,)[
schema.columns.keys()
] # set the column order according to schema
# set the column order according to schema
data_df[[c for c in schema.columns if c in data_df.columns]]
)
1 change: 1 addition & 0 deletions tests/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,7 @@ class Schema(pa.DataFrameModel):
state: Series[str]
city: Series[str]
price: Series[float]
postal_code: Optional[Series[int]] = pa.Field(nullable=True)

raw_data = [
{
Expand Down