-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add requested_schema argument to PyCapsule interface #13802
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
Conversation
66e66cd
to
6c4972d
Compare
6c4972d
to
e9dcac8
Compare
e9dcac8
to
62ff2db
Compare
62ff2db
to
38489c4
Compare
@@ -412,7 +412,7 @@ class DuckDBPyRelation: | |||
def list(self, column: str, groups: str = ..., window_spec: str = ..., projected_columns: str = ...) -> DuckDBPyRelation: ... | |||
|
|||
def arrow(self, batch_size: int = ...) -> pyarrow.lib.Table: ... | |||
def __arrow_c_stream__(self) -> object: ... | |||
def __arrow_c_stream__(self, requested_schema: Any) -> object: ... |
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'm not sure if this will produce any issues, but the spec document suggests typing this as object | None = None
https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html#protocol-typehints
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.
Actually, this will mess with type checkers as long as you don't have =None
Pylance doesn't allow this:
from typing import Protocol, Any
class ArrowStreamExportable(Protocol):
def __arrow_c_stream__(self, requested_schema: object | None = None) -> object: ...
def accepts_arrow(data: ArrowStreamExportable): ...
class ArrowObject:
def __arrow_c_stream__(self, requested_schema: Any) -> object: ...
obj = ArrowObject()
accepts_arrow(obj)
with error:
Argument of type "ArrowObject" cannot be assigned to parameter "data" of type "ArrowStreamExportable" in function "accepts_arrow"
"ArrowObject" is incompatible with protocol "ArrowStreamExportable"
"__arrow_c_stream__" is an incompatible type
Type "(requested_schema: Any) -> object" is not assignable to type "(requested_schema: object | None = None) -> object"
Parameter "requested_schema" is missing default argument
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.
Nice catch - thanks!
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!
38489c4
to
57a53d1
Compare
@@ -412,7 +412,7 @@ class DuckDBPyRelation: | |||
def list(self, column: str, groups: str = ..., window_spec: str = ..., projected_columns: str = ...) -> DuckDBPyRelation: ... | |||
|
|||
def arrow(self, batch_size: int = ...) -> pyarrow.lib.Table: ... | |||
def __arrow_c_stream__(self) -> object: ... | |||
def __arrow_c_stream__(self, requested_schema: Optional[object]) -> object: ... |
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.
You still need to provide = None
, see #13802 (comment)
57a53d1
to
8c4e21e
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.
Thanks 👍
Merge pull request duckdb/duckdb#13745 from pdet/decimal_cast Merge pull request duckdb/duckdb#13802 from WillAyd/add-requested-schema
Merge pull request duckdb/duckdb#13745 from pdet/decimal_cast Merge pull request duckdb/duckdb#13802 from WillAyd/add-requested-schema Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
This should fix the issue described in https://github.com/duckdb/duckdb/pull/13418/files#r1746662887