Skip to content

Commit

Permalink
refine some code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinLeeo committed Jun 17, 2024
1 parent 8d61881 commit 1212df2
Show file tree
Hide file tree
Showing 5 changed files with 456 additions and 315 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ python/tsfile/libtsfile.so
python/tsfile/libtsfile.so.1.0
python/tsfile/tsfile_pywrapper.cpython-310-x86_64-linux-gnu.so
python/tsfile/TsFile_cwrapper.h
python/tsfile/tsfile_pywrapper.cpp
python/data
20 changes: 20 additions & 0 deletions python/tsfile/tsfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from typing import overload
from pandas import DataFrame

TIMESTAMP_STR = "Time"


# default case -> Dataframe
@overload
Expand Down Expand Up @@ -110,5 +112,23 @@ def write_tsfile(
table_name: str,
data: DataFrame,
):
if data.empty:
return
column_names = data.columns.tolist()
column_types = data.dtypes

if TIMESTAMP_STR not in column_names:
raise AttributeError("Time column is missing")
if column_types[TIMESTAMP_STR] != "int64":
raise TypeError("Time column must be of type int64")
allowed_types = {"int64", "int32", "bool", "float32", "float64"}

# 检查每列的数据类型是否在允许的类型集合中
for col, dtype in column_types.items():
if dtype.name not in allowed_types:
raise TypeError(
f"Column '{col}' has an invalid type '{dtype}'."
)

writer = tsfile_writer(file_path)
writer.write_tsfile(table_name, data)
Loading

0 comments on commit 1212df2

Please sign in to comment.