Skip to content
Merged
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
60 changes: 41 additions & 19 deletions quasardb/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#

import logging
import warnings
from datetime import datetime
from functools import partial

Expand Down Expand Up @@ -175,35 +176,56 @@ def write_series(series, table, col_name, infer_types=True, dtype=None):
)


def query(cluster: quasardb.Cluster, query, index=None, blobs=False, numpy=True):
def query(
cluster: quasardb.Cluster,
query: str,
index: str = None,
blobs: bool = False,
numpy: bool = True,
):
"""
Execute a query and return the results as DataFrames. Returns a dict of
tablename / DataFrame pairs.

Parameters:
-----------
Execute *query* and return the result as a pandas DataFrame.

Parameters
----------
cluster : quasardb.Cluster
Active connection to the QuasarDB cluster
Active connection to the QuasarDB cluster.

query : str
The query to execute.
The query to execute.

blobs : bool or list
Determines which QuasarDB blob-columns should be returned as bytearrays; otherwise
they are returned as UTF-8 strings.

True means every blob column should be returned as byte-array, or a list will
specify which specific columns. Defaults to false, meaning all blobs are returned
as strings.
index : str | None, default None
Column to use as index. When None a synthetic index is created and
named “$index”.

blobs, numpy
DEPRECATED – no longer used. Supplying a non-default value raises a
DeprecationWarning and the argument is ignored.
"""
# ------------------------------------------------------------------ deprecations
if blobs is not False:
warnings.warn(
"`blobs` is deprecated and will be removed in a future version; "
"the argument is ignored.",
DeprecationWarning,
stacklevel=2,
)
if numpy is not True:
warnings.warn(
"`numpy` is deprecated and will be removed in a future version; "
"the argument is ignored.",
DeprecationWarning,
stacklevel=2,
)
# ------------------------------------------------------------------------------

logger.debug("querying and returning as DataFrame: %s", query)
(index, m) = qdbnp.query(cluster, query, index=index, dict=True)
df = pd.DataFrame(m)
index_vals, m = qdbnp.query(cluster, query, index=index, dict=True)

index_name = "$index" if index is None else index
Copy link

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting the magic string "$index" into a module-level constant to improve clarity and avoid duplication.

Suggested change
index_name = "$index" if index is None else index
index_name = DEFAULT_INDEX_NAME if index is None else index

Copilot uses AI. Check for mistakes.
index_obj = pd.Index(index_vals, name=index_name)

df.set_index(index, inplace=True)
return df
return pd.DataFrame(m, index=index_obj)


def stream_dataframes(
Expand Down