Skip to content

[Python] Add __getattr__ and __getitem__ implementations for DuckDBPyRelation#6624

Merged
Mytherin merged 4 commits intoduckdb:masterfrom
Tishj:pyrelation_getattr
Mar 9, 2023
Merged

[Python] Add __getattr__ and __getitem__ implementations for DuckDBPyRelation#6624
Mytherin merged 4 commits intoduckdb:masterfrom
Tishj:pyrelation_getattr

Conversation

@Tishj
Copy link
Contributor

@Tishj Tishj commented Mar 8, 2023

This adds the following syntax:
relation.column_of_relation
relation['column_of_relation']

Example:

import duckdb

duckdb.sql('create table tbl (name varchar, age int, date_of_birth timestamp)')
rel = duckdb.table('tbl')
# Create a projection on the table only selecting the name column
name_relation = rel.name
# Does the same as above
also_name_relation = rel['name']

Copy link
Collaborator

@Mytherin Mytherin left a 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! LGTM

@Tishj
Copy link
Contributor Author

Tishj commented Mar 9, 2023

Not sure what's up with this failure in https://github.com/duckdb/duckdb/actions/runs/4365008302/jobs/7635131271

It fails on OSError: zlib inflate failed: incorrect header check in the H2OAI tests, I would guess it's a network issue and the file wasn't downloaded properly?

@Mytherin
Copy link
Collaborator

Mytherin commented Mar 9, 2023

Yep that's a network issue

@Mytherin Mytherin requested a review from Mause March 9, 2023 11:06

void Close();

unique_ptr<DuckDBPyRelation> GetAttribute(const string &name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this just throws a TypeError if you do relation[None]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it can't implicitly convert it to string, but might be worth a test 👍

@Mytherin Mytherin merged commit 7c1b3db into duckdb:master Mar 9, 2023
@Tishj Tishj deleted the pyrelation_getattr branch November 7, 2025 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants