-
Notifications
You must be signed in to change notification settings - Fork 210
test: Add free-threading test suite and fix thread-safety issues #3807
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
base: main
Are you sure you want to change the base?
Changes from 11 commits
4c4578e
273bf7d
6986332
e83c830
6c91bee
580ecfe
72a3d19
ae0bbba
3a3a84f
0929d46
4b8c878
568c449
249a0d9
8051268
e1bf200
09395ec
28e332a
911f963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,13 @@ | |
| import duckdb | ||
| from duckdb import Expression | ||
|
|
||
| from narwhals._utils import Implementation, Version, extend_bool, isinstance_or_issubclass | ||
| from narwhals._utils import ( | ||
| Implementation, | ||
| Version, | ||
| extend_bool, | ||
| generate_temporary_column_name, | ||
| isinstance_or_issubclass, | ||
| ) | ||
| from narwhals.exceptions import ColumnNotFoundError | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -337,6 +343,26 @@ def join_column_names(*names: str) -> str: | |
| return ", ".join(str(col(name)) for name in names) | ||
|
|
||
|
|
||
| def temporary_view_name() -> str: | ||
| """Unique name for `DuckDBPyRelation.query`'s `virtual_table_name`. | ||
|
|
||
| `rel.query(view, sql)` registers `rel` as a view named `view` and runs `sql` on | ||
| `rel`'s own connection (see [relational api]). We prefer it to `duckdb.sql(statement)`, | ||
| which uses the global default connection and cannot see relations from other | ||
| connections (see [using connections in parallel pythonprograms]). | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it makes sense to have a helper to go along with this one that accepts two queries and verifies that they're from the same connection. I bet users will start seeing errors coming from queries on two different connections because of this. Also are there memory consequences for this change? The paragraph below indicates that these temporary views are never dropped. If this cost is per-thread, that might add up a lot.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right that the views are never dropped: I couldn't find a way we can just drop the view once the relation is built. Regarding the same-connection helper, similarly I couldn't find something exposed by a In both cases, I will run the questions by an agent and/or ask in a duckdb forum/github discussion to see if there is something I couldn't find from
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened two discussions in duckdb-python repository: duckdb/duckdb-python#580 and duckdb/duckdb-python#581 |
||
|
|
||
| The name must be unique per call: views persist and the lazy result re-binds by | ||
| name on execution, so a reused name shadows earlier views and corrupts their plans. | ||
| `rel.query` must also run in the frame whose locals the SQL references, as | ||
| [replacement scans] only see the caller's frame [3]. | ||
|
|
||
| [relational api]: https://duckdb.org/docs/current/clients/python/relational_api | ||
| [using connections in parallel pythonprograms]: https://duckdb.org/docs/current/clients/python/overview#using-connections-in-parallel-python-programs | ||
| [replacement scans]: https://duckdb.org/docs/current/clients/c/replacement_scans | ||
| """ | ||
| return generate_temporary_column_name(8, [], prefix="_narwhals_") | ||
|
|
||
|
|
||
| def generate_order_by_sql( | ||
| *order_by: str | Expression, descending: Sequence[bool], nulls_last: Sequence[bool] | ||
| ) -> str: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.