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
14 changes: 14 additions & 0 deletions python/tests/test_to_tsfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion python/tsfile/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down