Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

Edit: Used Copilot for this since it's straightforward and tested:
image


The DuckDB example in the homepage documentation used pandas-like methods (groupby(), mean(), sort_values(), tail()) on a DuckDB relation object, which raises AttributeError: This relation does not contain a column by the name of 'groupby'.

Changes

  • Replace duckdb.from_df() with explicit connection and table registration
  • Use SQL query with aggregation instead of chaining pandas methods
  • Call connection.query() instead of attempting pandas-like operations on relations

Before

df_duckdb = duckdb.from_df(df)
table = df_duckdb.groupby(['origin', 'mfr'])['mpg'].mean().sort_values().tail(5)
table.hvplot.barh('mfr', 'mpg', by='origin', stacked=True)

After

con = duckdb.connect(':memory:')
con.register('autompg', df)

query = """
SELECT origin, mfr, AVG(mpg) as mpg
FROM autompg
GROUP BY origin, mfr
ORDER BY mpg DESC
LIMIT 5
"""
table = con.query(query)
table.hvplot.barh('mfr', 'mpg', by='origin', stacked=True)
Original prompt

This section details on the original issue you should resolve

<issue_title>DuckDb reference example not working</issue_title>
<issue_description>Example from https://hvplot.holoviz.org/en/docs/latest/

Image
import duckdb
import hvplot.duckdb
from bokeh.sampledata.autompg import autompg_clean as df

df_duckdb = duckdb.from_df(df)
table = df_duckdb.groupby(['origin', 'mfr'])['mpg'].mean().sort_values().tail(5)
table.hvplot.barh('mfr', 'mpg', by='origin', stacked=True)
Traceback (most recent call last):
  File "/home/jovyan/repos/private/panel/script.py", line 6, in <module>
    table = df_duckdb.groupby(['origin', 'mfr'])['mpg'].mean().sort_values().tail(5)
            ^^^^^^^^^^^^^^^^^
AttributeError: This relation does not contain a column by the name of 'groupby'

duckdb==1.2.2
hvplot==0.11.2</issue_description>

Comments on the Issue (you are @copilot in this section)

@MarcSkovMadsen This would work
import duckdb
import hvplot.duckdb
from bokeh.sampledata.autompg import autompg_clean as df

# Create a DuckDB connection and register the DataFrame as a table
con = duckdb.connect(':memory:')
con.register('autompg', df)

# Query using DuckDB SQL to get the same result
query = """
SELECT origin, mfr, mpg
FROM (
    SELECT origin, mfr, AVG(mpg) as mpg
    FROM autompg
    GROUP BY origin, mfr
    ORDER BY mpg DESC
    LIMIT 5
)
ORDER BY mpg ASC
"""

table = con.execute(query)
table.hvplot.barh('mfr', 'mpg', by='origin', stacked=True)

Image</comment_new>
<comment_new>@hoxbro
I would suggest using table = con.query(query) instead of con.execute(query) as this is supported by narwhals:

Image</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix DuckDb reference example in documentation Fix DuckDB documentation example to use SQL queries instead of pandas-like API Dec 23, 2025
Copilot AI requested a review from ahuang11 December 23, 2025 17:30
@ahuang11 ahuang11 marked this pull request as ready for review December 23, 2025 18:25
@ahuang11 ahuang11 requested review from Azaya89 and maximlt December 23, 2025 18:25
@Azaya89
Copy link
Collaborator

Azaya89 commented Dec 24, 2025

LGTM, although I think the gif needs to be replaced as well to match the actual output.

table = con.query(query)
table.hvplot.barh('mfr', 'mpg', by='origin', stacked=True)
```
```{image} ./_static/home/pandas.gif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```{image} ./_static/home/pandas.gif
```{image} ./_static/home/duckdb.gif

This gif should be replaced with the current correct output

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.

DuckDb reference example not working

3 participants