-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[Python] Extend project
to accept a list of types + add DuckDBPyType class
#6777
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
[Python] Extend project
to accept a list of types + add DuckDBPyType class
#6777
Conversation
…t of DuckDBPyType
…e against a string - this makes this change backwards compatible, by supporting comparisons with for example, lists of stringified types
The implementation of the EnumType creation method is left as an exercise for the reader ;) |
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.
Some further ideas
…es for some of the creation methods, and made changes to the compare + constructor methods
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.
Thanks for the PR! Looks great. I think adding support for types is a great idea - some comments below:
…int], dict['a': str, 'c2': bool]
Could you have a look at fixing the merge conflicts? |
The failure seems unrelated? |
Pandas provides this method as Do we maybe also want to add the |
I think providing both options is sensible. Perhaps we should just rename it to be fully compatible? Or have both |
I think I'll add |
Thanks! LGTM |
This PR implements the feature request in #6706
project
on list of column typesThis allows you to provide a list of types to project on instead of column names, selecting all of the columns of the relation that match any of the provided types.
The implementation of this is likely temporarily, as discussed in the linked request.
Aiming to replace this when we have support for this functionality in core.
DuckDBPyType
I initially thought it was overkill to add a python class to represent our LogicalType, but we have thought of another use for this, so I have opted to add it anyways.
Primitives (defined on
duckdb.typing
)Creation methods
sqltype(type_str: str)
alias:
type
,dtype
create a type from parsing the
type_str
, this can also be used for user or extension defined typesstring_type(collation: str = "")
create VARCHAR type with optional collation
decimal_type(width: int, scale: int)
create a DECIMAL type of the given width + scale
enum_type(name: str, type: DuckDBPyType, values: list)
create en ENUM type from the 'values' list, cast astype
as underlying valuesarray_type(type: DuckDBPyType)
alias:
list_type
create a LIST type of the 'type' as child type
struct_type(fields: List[DuckDBPyType] | Dict[str, DuckDBPyType])
alias:
row_type
create a STRUCT type of the given field types (uses default names if given as List)
map_type(key: DuckDBPyType, value: DuckDBPyType)
create a MAP type out of the 'key' and 'value' types
union_type(members: List[DuckDBPyType] | Dict[str, DuckDBPyType])
create a UNION type of the given member types (similar to STRUCT)
Misc
Can be compared against strings
Converts implicitly from:
str
,builtins
types (str, bool, float etc..),list
,dict
,{'name', type, ..}
dictionary (to STRUCT),numpy
builtin typesint64
,bool_
,float32
etc.