@@ -111,33 +111,39 @@ 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 )
128
+ + timedelta (hours = len (self .exps )),
129
+ "figure_names" : [],
130
+ "backend" : FakeBackend (backend_name = backend_name ),
131
+ }
138
132
],
139
- ignore_index = True ,
133
+ columns = self . exps . columns ,
140
134
)
135
+ if len (self .exps ) > 0 :
136
+ self .exps = pd .concat (
137
+ [
138
+ self .exps ,
139
+ row ,
140
+ ],
141
+ ignore_index = True ,
142
+ )
143
+ else :
144
+ # Avoid the FutureWarning on concatenating empty DataFrames
145
+ # introduced in https://github.com/pandas-dev/pandas/pull/52532
146
+ self .exps = row
141
147
142
148
return experiment_id
143
149
@@ -293,35 +299,41 @@ def create_analysis_result(
293
299
# `IBMExperimentService.create_analysis_result`. Since `DbExperimentData` does not set it
294
300
# via kwargs (as it does with chisq), the user cannot control the time and the service
295
301
# alone decides about it. Here we've chosen to set the start date of the experiment.
296
- self . results = pd .concat (
302
+ row = pd .DataFrame (
297
303
[
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
- }
304
+ {
305
+ "result_data" : result_data ,
306
+ "result_id" : result_id ,
307
+ "result_type" : result_type ,
308
+ "device_components" : device_components ,
309
+ "experiment_id" : experiment_id ,
310
+ "quality" : quality ,
311
+ "verified" : verified ,
312
+ "tags" : tags ,
313
+ "backend_name" : self .exps .loc [self .exps .experiment_id == experiment_id ]
314
+ .iloc [0 ]
315
+ .backend_name ,
316
+ "chisq" : kwargs .get ("chisq" , None ),
317
+ "creation_datetime" : self .exps .loc [
318
+ self .exps .experiment_id == experiment_id
320
319
]
321
- ),
322
- ],
323
- ignore_index = True ,
320
+ .iloc [0 ]
321
+ .start_datetime ,
322
+ }
323
+ ]
324
324
)
325
+ if len (self .results ) > 0 :
326
+ self .results = pd .concat (
327
+ [
328
+ self .results ,
329
+ row ,
330
+ ],
331
+ ignore_index = True ,
332
+ )
333
+ else :
334
+ # Avoid the FutureWarning on concatenating empty DataFrames
335
+ # introduced in https://github.com/pandas-dev/pandas/pull/52532
336
+ self .results = row
325
337
326
338
# a helper method for updating the experiment's device components, see usage below
327
339
def add_new_components (expcomps ):
0 commit comments