@@ -152,7 +152,8 @@ def query(self,
152
152
chunked = False ,
153
153
chunk_size = 0 ,
154
154
method = "GET" ,
155
- dropna = True ):
155
+ dropna = True ,
156
+ data_frame_index = None ):
156
157
"""
157
158
Query data into a DataFrame.
158
159
@@ -181,6 +182,8 @@ def query(self,
181
182
containing all results within that chunk
182
183
:param chunk_size: Size of each chunk to tell InfluxDB to use.
183
184
:param dropna: drop columns where all values are missing
185
+ :param data_frame_index: the list of columns that
186
+ are used as DataFrame index
184
187
:returns: the queried data
185
188
:rtype: :class:`~.ResultSet`
186
189
"""
@@ -196,13 +199,14 @@ def query(self,
196
199
results = super (DataFrameClient , self ).query (query , ** query_args )
197
200
if query .strip ().upper ().startswith ("SELECT" ):
198
201
if len (results ) > 0 :
199
- return self ._to_dataframe (results , dropna )
202
+ return self ._to_dataframe (results , dropna ,
203
+ data_frame_index = data_frame_index )
200
204
else :
201
205
return {}
202
206
else :
203
207
return results
204
208
205
- def _to_dataframe (self , rs , dropna = True ):
209
+ def _to_dataframe (self , rs , dropna = True , data_frame_index = None ):
206
210
result = defaultdict (list )
207
211
if isinstance (rs , list ):
208
212
return map (self ._to_dataframe , rs ,
@@ -216,10 +220,15 @@ def _to_dataframe(self, rs, dropna=True):
216
220
key = (name , tuple (sorted (tags .items ())))
217
221
df = pd .DataFrame (data )
218
222
df .time = pd .to_datetime (df .time )
219
- df .set_index ('time' , inplace = True )
220
- if df .index .tzinfo is None :
221
- df .index = df .index .tz_localize ('UTC' )
222
- df .index .name = None
223
+
224
+ if data_frame_index :
225
+ df .set_index (data_frame_index , inplace = True )
226
+ else :
227
+ df .set_index ('time' , inplace = True )
228
+ if df .index .tzinfo is None :
229
+ df .index = df .index .tz_localize ('UTC' )
230
+ df .index .name = None
231
+
223
232
result [key ].append (df )
224
233
for key , data in result .items ():
225
234
df = pd .concat (data ).sort_index ()
0 commit comments