@@ -152,7 +152,8 @@ def query(self,
152152 chunked = False ,
153153 chunk_size = 0 ,
154154 method = "GET" ,
155- dropna = True ):
155+ dropna = True ,
156+ data_frame_index = None ):
156157 """
157158 Query data into a DataFrame.
158159
@@ -181,6 +182,8 @@ def query(self,
181182 containing all results within that chunk
182183 :param chunk_size: Size of each chunk to tell InfluxDB to use.
183184 :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
184187 :returns: the queried data
185188 :rtype: :class:`~.ResultSet`
186189 """
@@ -196,13 +199,14 @@ def query(self,
196199 results = super (DataFrameClient , self ).query (query , ** query_args )
197200 if query .strip ().upper ().startswith ("SELECT" ):
198201 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 )
200204 else :
201205 return {}
202206 else :
203207 return results
204208
205- def _to_dataframe (self , rs , dropna = True ):
209+ def _to_dataframe (self , rs , dropna = True , data_frame_index = None ):
206210 result = defaultdict (list )
207211 if isinstance (rs , list ):
208212 return map (self ._to_dataframe , rs ,
@@ -216,10 +220,15 @@ def _to_dataframe(self, rs, dropna=True):
216220 key = (name , tuple (sorted (tags .items ())))
217221 df = pd .DataFrame (data )
218222 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+
223232 result [key ].append (df )
224233 for key , data in result .items ():
225234 df = pd .concat (data ).sort_index ()
0 commit comments