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

Implement Pydantic V2 protocol #54034

Closed
wants to merge 4 commits into from

Conversation

Kludex
Copy link

@Kludex Kludex commented Jul 7, 2023

  1. What's the best file to add a test for this change? 😅
  2. Should I implement the one for pd.DataFrame as well on this PR?

@MarcoGorelli
Copy link
Member

thanks for your PR - could you show an example of how users would use this?

As in:

  • how they can use this now
  • how this PR changes/improves that

As for tests, maybe test_downstream.py?

@Kludex Kludex force-pushed the feat/pydantic-protocol branch from c536c9d to 28b7792 Compare July 7, 2023 10:26
Copy link
Member

@MarcoGorelli MarcoGorelli left a 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
Copy link
Member

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"))
Copy link
Member

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?

Copy link
Author

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:

image

Comment on lines +282 to +283
Series([1, 2, 3]),
Series(np.array([1, 2, 3])),
Copy link
Member

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

Copy link
Author

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.

Comment on lines +6230 to +6235
return core_schema.union_schema(
[
core_schema.is_instance_schema(Series),
core_schema.no_info_plain_validator_function(Series)
]
)
Copy link
Member

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?

Comment on lines +295 to +296
assert model.model_dump() == {}
assert model.model_json_schema() == {}
Copy link
Member

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?

Copy link
Author

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 👀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@mroeschke mroeschke left a 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

@Kludex
Copy link
Author

Kludex commented Jul 8, 2023

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)

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2023

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.

@github-actions github-actions bot added the Stale label Aug 8, 2023
@MarcoGorelli
Copy link
Member

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

@Kludex
Copy link
Author

Kludex commented Aug 8, 2023

It's active, and this is on my TODO list. 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Implement "Pydantic protocol"
3 participants