This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/tsfile.git


The following commit(s) were added to refs/heads/develop by this push:
     new 27b1051b8 Fix validation for DataFrame with only time column in 
`dataframe_to_tsfile` (#736)
27b1051b8 is described below

commit 27b1051b8c6a894c3737d8968ac20979ff6a86a2
Author: Hongzhi Gao <[email protected]>
AuthorDate: Wed Mar 4 18:49:14 2026 +0800

    Fix validation for DataFrame with only time column in `dataframe_to_tsfile` 
(#736)
    
    * fix readme logo
    
    * fix readme logo
    
    * fix readme badge
    
    * Fix validation for DataFrame with only time column in
---
 python/tests/test_to_tsfile.py | 14 ++++++++++++++
 python/tsfile/utils.py         |  3 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/python/tests/test_to_tsfile.py b/python/tests/test_to_tsfile.py
index 4e0481883..efd607feb 100644
--- a/python/tests/test_to_tsfile.py
+++ b/python/tests/test_to_tsfile.py
@@ -296,6 +296,20 @@ def test_dataframe_to_tsfile_no_data_columns():
             os.remove(tsfile_path)
 
 
+def test_dataframe_to_tsfile_only_time_column_raises():
+    """Only time column (no FIELD/TAG columns) must raise ValueError."""
+    tsfile_path = "test_only_time_column.tsfile"
+    try:
+        if os.path.exists(tsfile_path):
+            os.remove(tsfile_path)
+        df = pd.DataFrame({"time": [1, 2, 3]})
+        with pytest.raises(ValueError, match="at least one data column besides 
the time column"):
+            dataframe_to_tsfile(df, tsfile_path)
+    finally:
+        if os.path.exists(tsfile_path):
+            os.remove(tsfile_path)
+
+
 def test_dataframe_to_tsfile_time_column_not_found():
     tsfile_path = "test_dataframe_to_tsfile_time_err.tsfile"
     try:
diff --git a/python/tsfile/utils.py b/python/tsfile/utils.py
index 2e5fc05f8..723707bd1 100644
--- a/python/tsfile/utils.py
+++ b/python/tsfile/utils.py
@@ -287,7 +287,8 @@ def dataframe_to_tsfile(dataframe: pd.DataFrame,
         category = ColumnCategory.TAG if col in tag_columns_lower else 
ColumnCategory.FIELD
         column_schemas.append(ColumnSchema(col, ts_data_type, category))
 
-    if len(column_schemas) == 0:
+    data_columns = [s for s in column_schemas if s.get_category() != 
ColumnCategory.TIME]
+    if len(data_columns) == 0:
         raise ValueError("DataFrame must have at least one data column besides 
the time column")
 
     table_schema = TableSchema(table_name, column_schemas)

Reply via email to