@@ -1266,16 +1266,28 @@ def test_to_pandas():
12661266 np .testing .assert_equal (df ['u[0]' ], resp .inputs )
12671267 np .testing .assert_equal (df ['y[0]' ], resp .inputs * 5 )
12681268
1269+ # Multi-trace data
12691270 # https://github.com/python-control/python-control/issues/1087
12701271 model = ct .rss (
12711272 states = ['x0' , 'x1' ], outputs = ['y0' , 'y1' ],
12721273 inputs = ['u0' , 'u1' ], name = 'My Model' )
12731274 T = np .linspace (0 , 10 , 100 , endpoint = False )
12741275 X0 = np .zeros (model .nstates )
1275- res = ct .step_response (model , T = T , X0 = X0 , input = 0 )
1276+
1277+ res = ct .step_response (model , T = T , X0 = X0 , input = 0 ) # extract single trace
1278+ df = res .to_pandas ()
1279+ np .testing .assert_equal (
1280+ df [df ['trace' ] == 'From u0' ]['time' ], res .time )
1281+ np .testing .assert_equal (
1282+ df [df ['trace' ] == 'From u0' ]['y1' ], res .outputs ['y1' , 0 ])
1283+
1284+ res = ct .step_response (model , T = T , X0 = X0 ) # all traces
12761285 df = res .to_pandas ()
1277- np .testing .assert_equal (df ['time' ], res .time )
1278- np .testing .assert_equal (df ['y1' ], res .outputs ['y1' ])
1286+ for i , label in enumerate (res .trace_labels ):
1287+ np .testing .assert_equal (
1288+ df [df ['trace' ] == label ]['time' ], res .time )
1289+ np .testing .assert_equal (
1290+ df [df ['trace' ] == label ]['u0' ], res .inputs ['u0' , i ])
12791291
12801292
12811293@pytest .mark .skipif (pandas_check (), reason = "pandas installed" )
0 commit comments