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

fixes json schema issue #1704

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
46 changes: 33 additions & 13 deletions pandera/typing/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import numpy as np
import pandas as pd

from pandera.config import config_context
from pandera.engines import PYDANTIC_V2
from pandera.errors import SchemaError, SchemaInitError
from pandera.typing.common import (
Expand All @@ -30,12 +31,6 @@
)
from pandera.typing.formats import Formats

try:
from typing import get_args
except ImportError:
from typing_extensions import get_args


try:
from typing import _GenericAlias # type: ignore[attr-defined]
except ImportError: # pragma: no cover
Expand Down Expand Up @@ -190,13 +185,38 @@
def __get_pydantic_core_schema__(
cls, _source_type: Any, _handler: GetCoreSchemaHandler
) -> core_schema.CoreSchema:
schema_model = get_args(_source_type)[0]
return core_schema.no_info_plain_validator_function(
functools.partial(
cls.pydantic_validate,
schema_model=schema_model,
),
)

with config_context(validation_enabled=False):
schema_model = _source_type().__orig_class__.__args__[0]
if (schema_model.Config.from_format == "dict") and (

Check warning on line 191 in pandera/typing/pandas.py

View check run for this annotation

Codecov / codecov/patch

pandera/typing/pandas.py#L189-L191

Added lines #L189 - L191 were not covered by tests
schema_model.Config.from_format_kwargs == {"orient": "records"}
):
schema = schema_model.to_schema()
type_map = {

Check warning on line 195 in pandera/typing/pandas.py

View check run for this annotation

Codecov / codecov/patch

pandera/typing/pandas.py#L194-L195

Added lines #L194 - L195 were not covered by tests
"str": core_schema.str_schema(),
"int64": core_schema.int_schema(),
"float64": core_schema.float_schema(),
"bool": core_schema.bool_schema(),
"datetime64[ns]": core_schema.datetime_schema(),
}

return core_schema.list_schema(

Check warning on line 203 in pandera/typing/pandas.py

View check run for this annotation

Codecov / codecov/patch

pandera/typing/pandas.py#L203

Added line #L203 was not covered by tests
core_schema.typed_dict_schema(
{
i: core_schema.typed_dict_field(
type_map[str(j.dtype)]
)
for i, j in schema.columns.items()
},
)
)
else:
return core_schema.no_info_plain_validator_function(

Check warning on line 214 in pandera/typing/pandas.py

View check run for this annotation

Codecov / codecov/patch

pandera/typing/pandas.py#L214

Added line #L214 was not covered by tests
functools.partial(
cls.pydantic_validate,
schema_model=schema_model,
),
)

else:

Expand Down
Loading