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

hxd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 63d08a2  [CLIENT-PY] Fixed Situation where non-timeseries queries 
cannot be cast to df.
63d08a2 is described below

commit 63d08a28db4dd0939550c637219e8db8e7225559
Author: julian <[email protected]>
AuthorDate: Thu Apr 8 15:29:47 2021 +0200

    [CLIENT-PY] Fixed Situation where non-timeseries queries cannot be cast to 
df.
---
 client-py/iotdb/utils/SessionDataSet.py | 10 ++++++++--
 client-py/tests/test_dataframe.py       | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/client-py/iotdb/utils/SessionDataSet.py 
b/client-py/iotdb/utils/SessionDataSet.py
index f0f7266..60439ae 100644
--- a/client-py/iotdb/utils/SessionDataSet.py
+++ b/client-py/iotdb/utils/SessionDataSet.py
@@ -144,18 +144,24 @@ def resultset_to_pandas(result_set: SessionDataSet) -> 
pd.DataFrame:
 
     value_dict = {}
 
+    if "Time" in column_names:
+        offset = 1
+    else:
+        offset = 0
+
     for i in range(len(column_names)):
         value_dict[column_names[i]] = []
 
     while result_set.has_next():
         record = result_set.next()
 
-        value_dict["Time"].append(record.get_timestamp())
+        if "Time" in column_names:
+            value_dict["Time"].append(record.get_timestamp())
 
         for col in range(len(record.get_fields())):
             field: Field = record.get_fields()[col]
 
-            value_dict[column_names[col + 1]].append(get_typed_point(field))
+            value_dict[column_names[col + 
offset]].append(get_typed_point(field))
 
     return pd.DataFrame(value_dict)
 
diff --git a/client-py/tests/test_dataframe.py 
b/client-py/tests/test_dataframe.py
index 30f38e3..cd47b30 100644
--- a/client-py/tests/test_dataframe.py
+++ b/client-py/tests/test_dataframe.py
@@ -39,3 +39,24 @@ def test_simple_query():
 
     assert list(df.columns) == ["Time", "root.device.pressure"]
     assert_array_equal(df.values, [[123.0, 15.0]])
+
+
+def test_non_time_query():
+    with IoTDBContainer("apache/iotdb:0.11.2") as db:
+        db: IoTDBContainer
+        session = Session(db.get_container_host_ip(), 
db.get_exposed_port(6667))
+        session.open(False)
+
+        # Write data
+        session.insert_str_record("root.device", 123, "pressure", "15.0")
+
+        # Read
+        session_data_set = session.execute_query_statement("SHOW TIMESERIES")
+        df = session_data_set.todf()
+
+        session.close()
+
+    assert list(df.columns) == ['timeseries', 'alias', 'storage group', 
'dataType', 'encoding', 'compression', 'tags',
+                                'attributes']
+    assert_array_equal(df.values,
+                       [['root.device.pressure', None, 'root.device', 'FLOAT', 
'GORILLA', 'SNAPPY', None, None]])

Reply via email to