Repository navigation
Compose transform schemas with Polars DataTypes, not native Python types. - #2493
Merged
Merged
Conversation
Contributor
Author
|
cc @leninworld |
not native Python types. A closer read of * https://docs.pola.rs/api/python/stable/reference/dataframe/index.html suggests that even though some wording says a dict of {name:type} pairs a Python "type" is not intended by the word "type", but a Polars "DataType". The correspondences between MySQL field types and Polars schema DataTypes can no longer be mapped out coherently as a dictionary, since * there are more and more special cases such as signed/unsigned integers * the polars library is conditionally imported, so the logic containing references to its types must be deferred Therefore, the mapping system is written out as a series of cluttered "if" blocks, though some meaningful type collections are grouped at the top of the file. This change incidentally fixes a bug in which NEWDATE was cast to str. Limitations around GEOMETRY and SET result fields are documented. TEXT_BINARY_TYPES is recast to STRING_BINARY_FIELD_TYPES to match the name of the Polars types. A couple of todo comments are added. Interval temporal types do not seem to be covered. Should they be? It is still not clear that there is any measurable performance gain for writing schemas over letting Polars infer types, but this method definitely solves some edge cases which led to sometimes-confusing errors in the REPL.
rolandwalker
force-pushed
the
RW/transform-shemas-as-polars-types
branch
from
December 3, 2026 14:16
0ef7c33 to
8e48a88
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
A closer read of
suggests that even though some wording says
a Python
typeis not intended by the word "type", but a PolarsDataType.The correspondences between MySQL field types and Polars schema
DataTypescan no longer be mapped out coherently as a dictionary, sincepolarslibrary is conditionally imported, so the logic containing references to its types must be deferredTherefore, the mapping system is written out as a series of cluttered
ifblocks, though some meaningful type collections are grouped at the top of the file.This change incidentally fixes a bug in which
NEWDATEwas cast tostr.Limitations around
GEOMETRYandSETresult fields are documented.TEXT_BINARY_TYPESis recast toSTRING_BINARY_FIELD_TYPESto match the name of the Polars types.A couple of todo comments are added. Interval temporal types do not seem to be covered. Should they be?
It is still not clear that there is any measurable performance gain for writing schemas over letting Polars infer types, but this method definitely solves some edge cases which led to sometimes-confusing errors in the REPL.
Checklist
changelog.mdfile.mycli/AUTHORS.txtfile (or it's already there).