Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/include/duckdb/main/client_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct ClientProperties {
arrow_lossless_conversion(lossless_conversion), arrow_output_version(arrow_output_version),
client_context(client_context) {
}
ClientProperties() {};

string time_zone = "UTC";
ArrowOffsetSize arrow_offset_size = ArrowOffsetSize::REGULAR;
Expand Down
4 changes: 2 additions & 2 deletions tools/pythonpkg/src/include/duckdb_python/pyrelation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace duckdb {
struct DuckDBPyRelation {
public:
explicit DuckDBPyRelation(shared_ptr<Relation> rel);
explicit DuckDBPyRelation(unique_ptr<DuckDBPyResult> result);
explicit DuckDBPyRelation(shared_ptr<DuckDBPyResult> result);
~DuckDBPyRelation();

public:
Expand Down Expand Up @@ -288,7 +288,7 @@ struct DuckDBPyRelation {
shared_ptr<Relation> rel;
vector<LogicalType> types;
vector<string> names;
unique_ptr<DuckDBPyResult> result;
shared_ptr<DuckDBPyResult> result;
std::string rendered_result;
};

Expand Down
2 changes: 2 additions & 0 deletions tools/pythonpkg/src/include/duckdb_python/pyresult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ struct DuckDBPyResult {
const vector<string> &GetNames();
const vector<LogicalType> &GetTypes();

ClientProperties GetClientProperties();

private:
void FillNumpy(py::dict &res, idx_t col_idx, NumpyResultConversion &conversion, const char *name);

Expand Down
11 changes: 9 additions & 2 deletions tools/pythonpkg/src/pyrelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ DuckDBPyRelation::~DuckDBPyRelation() {
rel.reset();
}

DuckDBPyRelation::DuckDBPyRelation(unique_ptr<DuckDBPyResult> result_p) : rel(nullptr), result(std::move(result_p)) {
DuckDBPyRelation::DuckDBPyRelation(shared_ptr<DuckDBPyResult> result_p) : rel(nullptr), result(std::move(result_p)) {
if (!result) {
throw InternalException("DuckDBPyRelation created without a result");
}
Expand Down Expand Up @@ -984,7 +984,14 @@ PolarsDataFrame DuckDBPyRelation::ToPolars(idx_t batch_size, bool lazy) {
ArrowSchema arrow_schema;
auto result_names = names;
QueryResult::DeduplicateColumns(result_names);
auto client_properties = rel->context->GetContext()->GetClientProperties();
ClientProperties client_properties;
if (rel) {
client_properties = rel->context->GetContext()->GetClientProperties();
} else if (result) {
client_properties = result->GetClientProperties();
} else {
throw InternalException("DuckDBPyRelation To Polars must have a valid relation or result");
}
ArrowConverter::ToArrowSchema(&arrow_schema, types, result_names, client_properties);
py::list batches;
// Now we create an empty arrow table
Expand Down
4 changes: 4 additions & 0 deletions tools/pythonpkg/src/pyresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ DuckDBPyResult::~DuckDBPyResult() {
}
}

ClientProperties DuckDBPyResult::GetClientProperties() {
return result->client_properties;
}

const vector<string> &DuckDBPyResult::GetNames() {
if (!result) {
throw InternalException("Calling GetNames without a result object");
Expand Down
8 changes: 8 additions & 0 deletions tools/pythonpkg/tests/fast/arrow/test_polars.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ def test_polars_from_json_error(self, duckdb_cursor):
my_res = duckdb.query("select my_str from my_table where my_str != 'y'")
assert my_res.fetchall() == [('x',)]

def test_polars_lazy_from_conn(self, duckdb_cursor):
duckdb_conn = duckdb.connect()

result = duckdb_conn.execute("SELECT 42 as bla")

lazy_df = result.pl(lazy=True)
assert lazy_df.collect().to_dicts() == [{'bla': 42}]

def test_polars_lazy(self, duckdb_cursor):
con = duckdb.connect()
con.execute("Create table names (a varchar, b integer)")
Expand Down
Loading