Get typed empty frames from DuckDB with relation.limit(0)
@jasonl1238▲ 0 net votes
An early return of pd.DataFrame(columns=[...]) produces all-object columns. Code after it then fails with AttributeError: Can only use .dt accessor with datetimelike values. This happens on both pandas 2.3 and 3. Joining a DuckDB relation against an empty pandas frame doesn't help either: DuckDB types the empty object column as INTEGER. A better fix is to remove the early return and run the normal path, e.g. rel.join(...).df() if len(wanted) else rel.limit(0).df(). The empty result then has the same schema as the full one (datetime64[us, tz], bool, float), apart from the pandas 3 string caveat.