@@ -111,33 +111,38 @@ def create_experiment(
111
111
# backend - the query methods `experiment` and `experiments` are supposed to return an
112
112
# an instantiated backend object, and not only the backend name. We assume that the fake
113
113
# service works with the fake backend (class FakeBackend).
114
- self . exps = pd .concat (
114
+ row = pd .DataFrame (
115
115
[
116
- self .exps ,
117
- pd .DataFrame (
118
- [
119
- {
120
- "experiment_type" : experiment_type ,
121
- "experiment_id" : experiment_id ,
122
- "parent_id" : parent_id ,
123
- "backend_name" : backend_name ,
124
- "metadata" : metadata ,
125
- "job_ids" : job_ids ,
126
- "tags" : tags ,
127
- "notes" : notes ,
128
- "share_level" : kwargs .get ("share_level" , None ),
129
- "device_components" : [],
130
- "start_datetime" : datetime (2022 , 1 , 1 )
131
- + timedelta (hours = len (self .exps )),
132
- "figure_names" : [],
133
- "backend" : FakeBackend (backend_name = backend_name ),
134
- }
135
- ],
136
- columns = self .exps .columns ,
137
- ),
116
+ {
117
+ "experiment_type" : experiment_type ,
118
+ "experiment_id" : experiment_id ,
119
+ "parent_id" : parent_id ,
120
+ "backend_name" : backend_name ,
121
+ "metadata" : metadata ,
122
+ "job_ids" : job_ids ,
123
+ "tags" : tags ,
124
+ "notes" : notes ,
125
+ "share_level" : kwargs .get ("share_level" , None ),
126
+ "device_components" : [],
127
+ "start_datetime" : datetime (2022 , 1 , 1 ) + timedelta (hours = len (self .exps )),
128
+ "figure_names" : [],
129
+ "backend" : FakeBackend (backend_name = backend_name ),
130
+ }
138
131
],
139
- ignore_index = True ,
132
+ columns = self . exps . columns ,
140
133
)
134
+ if len (self .exps ) > 0 :
135
+ self .exps = pd .concat (
136
+ [
137
+ self .exps ,
138
+ row ,
139
+ ],
140
+ ignore_index = True ,
141
+ )
142
+ else :
143
+ # Avoid the FutureWarning on concatenating empty DataFrames
144
+ # introduced in https://github.com/pandas-dev/pandas/pull/52532
145
+ self .exps = row
141
146
142
147
return experiment_id
143
148
@@ -293,35 +298,39 @@ def create_analysis_result(
293
298
# `IBMExperimentService.create_analysis_result`. Since `DbExperimentData` does not set it
294
299
# via kwargs (as it does with chisq), the user cannot control the time and the service
295
300
# alone decides about it. Here we've chosen to set the start date of the experiment.
296
- self . results = pd .concat (
301
+ row = pd .DataFrame (
297
302
[
298
- self .results ,
299
- pd .DataFrame (
300
- [
301
- {
302
- "result_data" : result_data ,
303
- "result_id" : result_id ,
304
- "result_type" : result_type ,
305
- "device_components" : device_components ,
306
- "experiment_id" : experiment_id ,
307
- "quality" : quality ,
308
- "verified" : verified ,
309
- "tags" : tags ,
310
- "backend_name" : self .exps .loc [self .exps .experiment_id == experiment_id ]
311
- .iloc [0 ]
312
- .backend_name ,
313
- "chisq" : kwargs .get ("chisq" , None ),
314
- "creation_datetime" : self .exps .loc [
315
- self .exps .experiment_id == experiment_id
316
- ]
317
- .iloc [0 ]
318
- .start_datetime ,
319
- }
320
- ]
321
- ),
322
- ],
323
- ignore_index = True ,
303
+ {
304
+ "result_data" : result_data ,
305
+ "result_id" : result_id ,
306
+ "result_type" : result_type ,
307
+ "device_components" : device_components ,
308
+ "experiment_id" : experiment_id ,
309
+ "quality" : quality ,
310
+ "verified" : verified ,
311
+ "tags" : tags ,
312
+ "backend_name" : self .exps .loc [self .exps .experiment_id == experiment_id ]
313
+ .iloc [0 ]
314
+ .backend_name ,
315
+ "chisq" : kwargs .get ("chisq" , None ),
316
+ "creation_datetime" : self .exps .loc [self .exps .experiment_id == experiment_id ]
317
+ .iloc [0 ]
318
+ .start_datetime ,
319
+ }
320
+ ]
324
321
)
322
+ if len (self .results ) > 0 :
323
+ self .results = pd .concat (
324
+ [
325
+ self .results ,
326
+ row ,
327
+ ],
328
+ ignore_index = True ,
329
+ )
330
+ else :
331
+ # Avoid the FutureWarning on concatenating empty DataFrames
332
+ # introduced in https://github.com/pandas-dev/pandas/pull/52532
333
+ self .results = row
325
334
326
335
# a helper method for updating the experiment's device components, see usage below
327
336
def add_new_components (expcomps ):
0 commit comments