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
12 changes: 11 additions & 1 deletion quasardb/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,17 @@ def read_dataframe(conn: quasardb.Cluster, table, **kwargs):
# dataframes.
dfs = stream_dataframe(conn, table, **kwargs)

return pd.concat(dfs)
# if result of stream_dataframe is empty this could result in ValueError on pd.concat()
# as stream_dataframe is a generator there is no easy way to check for this condition without evaluation
# the most simple way is to catch the ValueError and return an empty DataFrame
try:
return pd.concat(dfs, copy=False)
except ValueError as e:
logger.error(
"Error while concatenating dataframes. This can happen if result set is empty. Returning empty dataframe. Error: %s",
e,
)
return pd.DataFrame()
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

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

Returning an empty DataFrame without any columns may break downstream code expecting the original table schema; consider initializing with the table's column names to preserve schema.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same behavior as qdbpd.query function



def _extract_columns(df, cinfos):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,22 @@ def test_retries(
)

assert seen == True


def test_read_dataframe_empty_table_sc16881(qdbd_connection, table_name):
"""
Ensures qdbpd.read_dataframe returns an empty DataFrame when the table exists but contains no data.

Previously this raised ValueError due to pd.concat() on an empty result set.
"""
table = qdbd_connection.ts(table_name)

table_config = [
quasardb.ColumnInfo(quasardb.ColumnType.Double, "d"),
]

table.create(table_config)

df = qdbpd.read_dataframe(qdbd_connection, table)

assert df.empty