You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tsfile.apache.org by ji...@apache.org on 2026/03/05 04:31:43 UTC
(tsfile) branch develop updated: Fix/infer object column type bool (#737)
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 7c01e4f00 Fix/infer object column type bool (#737)
7c01e4f00 is described below
commit 7c01e4f003e188af0aac38ca0d9bc4fd1e6204e5
Author: Hongzhi Gao <76...@qq.com>
AuthorDate: Thu Mar 5 12:31:38 2026 +0800
Fix/infer object column type bool (#737)
* support bool type in infer_object_column_type
* infer_object_column_type ut
---
python/tests/test_dataframe.py | 10 +++++++++-
python/tsfile/tsfile_table_writer.py | 4 +++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/python/tests/test_dataframe.py b/python/tests/test_dataframe.py
index c8c543dfb..e40ff32a0 100644
--- a/python/tests/test_dataframe.py
+++ b/python/tests/test_dataframe.py
@@ -26,7 +26,7 @@ from tsfile import ColumnSchema, TableSchema, TSDataType, TIME_COLUMN
from tsfile import TsFileTableWriter, ColumnCategory
from tsfile import to_dataframe
from tsfile.exceptions import ColumnNotExistError, TypeMismatchError
-from tsfile.tsfile_table_writer import validate_dataframe_for_tsfile
+from tsfile.tsfile_table_writer import validate_dataframe_for_tsfile, infer_object_column_type
def convert_to_nullable_types(df):
@@ -51,6 +51,14 @@ def convert_to_nullable_types(df):
return df
+def test_infer_object_column_type_bool():
+ """infer_object_column_type should infer BOOLEAN for object column containing bool values."""
+ s_true = pd.Series([True, False], dtype=object)
+ assert infer_object_column_type(s_true) == TSDataType.BOOLEAN
+ s_false = pd.Series([False], dtype=object)
+ assert infer_object_column_type(s_false) == TSDataType.BOOLEAN
+
+
def test_write_dataframe_basic():
table = TableSchema("test_table",
[ColumnSchema("device", TSDataType.STRING, ColumnCategory.TAG),
diff --git a/python/tsfile/tsfile_table_writer.py b/python/tsfile/tsfile_table_writer.py
index 499b5843f..a8f7805d3 100644
--- a/python/tsfile/tsfile_table_writer.py
+++ b/python/tsfile/tsfile_table_writer.py
@@ -69,10 +69,12 @@ def infer_object_column_type(column_series: pd.Series) -> TSDataType:
return TSDataType.BLOB
if isinstance(value, (date, datetime)):
return TSDataType.DATE
+ if isinstance(value, bool):
+ return TSDataType.BOOLEAN
if isinstance(value, str):
return TSDataType.STRING
raise TypeError(
- f"Cannot infer type from object column: expected str/bytes/date, got {type(value).__name__}: {value!r}"
+ f"Cannot infer type from object column: expected str/bytes/date/bool, got {type(value).__name__}: {value!r}"
)