Skip to content

Commit e3ba398

Browse files
committed
add to_dataframe annotation.
1 parent 7cf9358 commit e3ba398

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

python/tsfile/utils.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,64 @@ def to_dataframe(file_path: str,
3232
end_time: Optional[int] = None,
3333
max_row_num: Optional[int] = None,
3434
as_iterator: bool = False) -> Union[pd.DataFrame, Iterator[pd.DataFrame]]:
35+
"""
36+
Read data from a TsFile and convert it into a Pandas DataFrame or
37+
an iterator of DataFrames.
38+
39+
This function supports both table-model and tree-model TsFiles.
40+
Users can filter data by table name, column names, time range,
41+
and maximum number of rows.
42+
43+
Parameters
44+
----------
45+
file_path : str
46+
Path to the TsFile to be read.
47+
48+
table_name : Optional[str], default None
49+
Name of the table to query in table-model TsFiles.
50+
If None and the file is in table model, the first table
51+
found in the schema will be used.
52+
53+
column_names : Optional[list[str]], default None
54+
List of column names to query.
55+
- If None, all columns will be returned.
56+
- Column existence will be validated in table-model TsFiles.
57+
58+
start_time : Optional[int], default None
59+
Start timestamp for the query.
60+
If None, the minimum int64 value is used.
61+
62+
end_time : Optional[int], default None
63+
End timestamp for the query.
64+
If None, the maximum int64 value is used.
65+
66+
max_row_num : Optional[int], default None
67+
Maximum number of rows to read.
68+
- If None, all available rows will be returned.
69+
- When `as_iterator` is False, the final DataFrame will be
70+
truncated to this size if necessary.
71+
72+
as_iterator : bool, default False
73+
Whether to return an iterator of DataFrames instead of
74+
a single concatenated DataFrame.
75+
- True: returns an iterator yielding DataFrames in batches
76+
- False: returns a single Pandas DataFrame
77+
78+
Returns
79+
-------
80+
Union[pandas.DataFrame, Iterator[pandas.DataFrame]]
81+
- A Pandas DataFrame if `as_iterator` is False
82+
- An iterator of Pandas DataFrames if `as_iterator` is True
83+
84+
Raises
85+
------
86+
TableNotExistError
87+
If the specified table name does not exist in a table-model TsFile.
88+
89+
ColumnNotExistError
90+
If any specified column does not exist in the table schema.
91+
"""
92+
3593
def _gen(is_iterator: bool) -> Iterator[pd.DataFrame]:
3694
_table_name = table_name
3795
_column_names = column_names

0 commit comments

Comments
 (0)