Skip to content
Draft
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
4 changes: 2 additions & 2 deletions pkg-py/src/querychat/_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def get_schema(self, *, categorical_threshold: int) -> str:
elif dtype == nw.Boolean:
sql_type = "BOOLEAN"
elif dtype == nw.Datetime:
sql_type = "TIME"
sql_type = "TIMESTAMP"
elif dtype == nw.Date:
sql_type = "DATE"
else:
Expand All @@ -224,7 +224,7 @@ def get_schema(self, *, categorical_threshold: int) -> str:
categories = unique_values.to_list()
categories_str = ", ".join([f"'{c}'" for c in categories])
column_info.append(f" Categorical values: {categories_str}")
elif sql_type in ["INTEGER", "FLOAT", "DATE", "TIME"]:
elif sql_type in ["INTEGER", "FLOAT", "DATE", "TIMESTAMP"]:
rng = self._df[column].min(), self._df[column].max()
if rng[0] is None and rng[1] is None:
column_info.append(" Range: NULL to NULL")
Expand Down
24 changes: 24 additions & 0 deletions pkg-py/tests/test_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,27 @@ def test_check_query_escape_hatch_accepts_various_values(monkeypatch):
for value in ["true", "TRUE", "1", "yes", "YES"]:
monkeypatch.setenv("QUERYCHAT_ENABLE_UPDATE_QUERIES", value)
check_query("INSERT INTO table VALUES (1)") # Should not raise


def test_dataframe_source_datetime_type_mapping():
"""Test that datetime columns are mapped to TIMESTAMP, not TIME."""
# Create DataFrame with datetime column
test_df = pd.DataFrame(
{
"id": [1, 2, 3],
"name": ["a", "b", "c"],
"created_at": pd.to_datetime(["2023-01-01 10:00:00", "2023-06-15 14:30:00", "2023-12-31 23:59:59"]),
}
)

source = DataFrameSource(test_df, "test_table")
schema = source.get_schema(categorical_threshold=5)

# Datetime columns should be TIMESTAMP, not TIME
assert "- created_at (TIMESTAMP)" in schema
assert "- created_at (TIME)" not in schema

# Should also show range for datetime columns
assert "Range:" in schema

source.cleanup()