-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
Implement Pydantic V2 protocol #54034
Conversation
thanks for your PR - could you show an example of how users would use this? As in:
As for tests, maybe |
c536c9d
to
28b7792
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally favourable to the idea
can you run the code checks as well please? check the contributing guide for how
@@ -45,6 +45,7 @@ dependencies: | |||
- py | |||
- psycopg2>=2.9.3 | |||
- pyarrow>=7.0.0 | |||
- pydantic>=2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a few more files where this needs to be added
|
||
@classmethod | ||
def __get_pydantic_core_schema__(cls, source_type: Type[Any], handler: GetCoreSchemaHandler) -> CoreSchema: | ||
pyd_core = cast("pydantic_core", import_optional_dependency("pydantic_core")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you casting to pydantic_core
? is that a type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pydantic_core
is a package: https://github.com/pydantic/pydantic-core - a dependency of Pydantic.
You can use cast()
with the module to have your IDE understand what you are doing:

Series([1, 2, 3]), | ||
Series(np.array([1, 2, 3])), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two are the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I actually should have used [1, 2,3]
and np.array[1, 2, 3]
without the Series
. I'll fix it.
return core_schema.union_schema( | ||
[ | ||
core_schema.is_instance_schema(Series), | ||
core_schema.no_info_plain_validator_function(Series) | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you explain what these do please?
assert model.model_dump() == {} | ||
assert model.model_json_schema() == {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you explain these two lines please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is not right. I couldn't set up pandas
locally, so I was expecting the pipeline to show me the results 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I'd suggest following https://pandas.pydata.org/docs/dev/development/contributing_environment.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If #53999 (comment) is true, then adding the pydantic protocol in pandas directly isn't a good idea if the protocol could differ on the use case
There was a miscommunication. This is what I meant: #53999 (comment) |
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
closing as it looks like this is no longer active but I'm interested in the idea - if explain it a bit more clearly, then am open to discussing this further |
It's active, and this is on my TODO list. 🤷♂️ |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.pd.DataFrame
as well on this PR?