Puzzleshot #027 - Pandas don't (always) Quack

raw data→pandas→duckdb→quack→result

Your DataFrame exists. Your Quack client can’t see it. Why?

Over the last two puzzles we shared a database over Quack and then listened in on the conversation. This puzzle, we serve a pandas DataFrame the same way.

The setup:

A Python script that starts a Quack server (the same call as in #025) and holds a DataFrame:

import duckdb
import pandas as pd

test_df = pd.DataFrame({"i": [1, 2, 3, 4], "j": ["one", "two", "three", "four"]})
duckdb.execute("INSTALL quack; LOAD quack;")
duckdb.execute("CALL quack_serve(token = 'my_token');")

Keep the script running (an input() call at the end works), because the server stops when the process exits. From another terminal, connect the way we did in #025:

ATTACH 'quack:localhost' AS qk (TOKEN 'my_token');
CONNECT qk;
SELECT * FROM testing;

The challenge:

Round 1: Make the DataFrame queryable from the client as a table called testing. Try all three, each in a fresh run of the script:

  1. duckdb.register(“testing”, test_df)
  2. duckdb.execute(“CREATE VIEW testing AS SELECT * FROM test_df”)
  3. duckdb.execute(“CREATE TABLE testing AS SELECT * FROM test_df”)

Which ones work, and why?

Round 2: Add a row to the DataFrame. Does the client see it? How do you make it?

Things to consider:

Keep everything on localhost with a throwaway token.

Reveal solution

This puzzle we tried three ways to share a DataFrame over Quack. Only one of them works.

Way 1 - register():

duckdb.register("testing", test_df)

The client says the table doesn’t exist. register() creates a temporary view that belongs to the connection that registered it, and the Quack client is a different session. The same thing happens with a second connection inside Python: a registered DataFrame is visible only to the connection that registered it.

Way 2 - CREATE VIEW:

duckdb.execute("CREATE VIEW testing AS SELECT * FROM test_df")

This one is sneakier. The view exists, and the client can see it, but querying it fails because it can’t find test_df. A regular view stores a query, not data. The name test_df only resolves through a Python replacement scan, which looks for variables in your Python code, and a remote Quack session has no Python code to look in.

Way 3 - CREATE TABLE AS:

duckdb.execute("CREATE TABLE testing AS SELECT * FROM test_df")

This works. A real table holds its data inside the database, so any connection can read it, with no Python session needed. The catch is that it’s a copy.

Round 2 - updating the DataFrame:

Adding a row to the DataFrame doesn’t change the table, because the table is a snapshot of the data as it was when you created it. To refresh it, rebuild it:

duckdb.execute("CREATE OR REPLACE TABLE testing AS SELECT * FROM test_df")

After that, the client sees the new data.

The things to consider:

Which can be resolved without your Python session? Only the table, because it holds its own data. The registered view lives on one connection, and the regular view depends on a Python variable.

What does each one store? The registered view and the regular view store a query that points back at your DataFrame. The table stores the data itself.

What happens when the script exits? The server stops, and since the default database lives in memory, the table disappears with it.

The takeaway:

A DataFrame is a Python object, and a Quack server is a database. To share the data, move it into the database.