-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix and change table sorting in Python #903
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't agree with adding this protected variable in multiple places. There are other ways to do this. For example, add an
__init__
function everywhere to add the required keys to the dict.But I am trying to look a bit further. It would be better if we receive this information from the julia code. For example, by adding it in the schemas and reading the schemas in python. Would that be something that is possible with pydantic?
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.
_sort_keys
was already used, falling back to a wrong default if it wasn't present. This PR removes the wrong default and requires explicitly stating the correct sorting order.If possible I agree it would be nice to share this or run this through pydantic. I'd like to keep this PR focused on a bugfix and not add a refactor on top.
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.
@visr @evetion take a look at feat/sort-keys-in-tablemodel. I don't have it working yet. But to me it seems like we need to put the sort keys inside of the table model as some class var which depends per initialization. Or maybe in another way. Just a Field?
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.
I have been playing a bit more with this, and it seems to me that the best option would be to make the sort_keys an instance Field
I set it to init_var, so it can never be changed afterwards, and I set it to exclude, because the data is always set in python.
The only problem that I still had was the moment that you set a pandas DataFrame, because then it tells me that:
I believe we could solve this by using a different scheme for custom data types, instead of the
@model_validator
as described here: https://docs.pydantic.dev/latest/concepts/types/#custom-typesThere 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.
Is init_var=True needed? Because if you set a DataFrame, the TableModel already exists, including its specific sort_keys. Ideally we get that from somewhere.
Fully agree, but I couldn't find a way of doing so. It requires some custom info passed to the JSON Schema, the https://github.com/koxudaxi/datamodel-code-generator/, to read it and pass it into some class as a private field, or Config option, that we here can pick up on.
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.
I created #956 for the first effort on getting the sort_keys in pydantic. You could decide to enhance the ticket, or otherwise just make a new ticket to get the info from Julia.