Ch_5_01_backtest_with_trades: Backtest data is series and not dataframe

I am attempting to run the

returns, positions, transactions = extract_rets_pos_txn_from_zipline(backtest)

line of the file ‘05_strategy_evaluation/01_backtest_with_trades.ipynb’ and running into an issue where the data from the ‘run_algorithm’ command shows an output in my IDE but no data is saved in the ‘backtest’ variable which I can inspect with the ‘data viewer’ extension in VS Code IDE.

The output from ‘run_algorithm’ is similar to the expected output from Stefan’s example, but does not include the summary at the end as his does. My output is below:

[ 15:35:38.714594]: INFO: 2013-01-14 | Longs: 13 | Shorts:  3 | 10,027,422.36
...
[ 15:38:15.724060]: INFO: 2016-12-19 | Longs: 13 | Shorts:  2 | 10,871,411.67
[ 15:38:16.463173]: INFO: 2016-12-27 | Longs: 12 | Shorts:  1 | 10,815,943.67

The next line

returns, positions, transactions = extract_rets_pos_txn_from_zipline(backtest)

returns an attribute error that reads as follows:

/tmp/ipykernel_2246/3074314327.py in ?()
----> 1 returns, positions, transactions = extract_rets_pos_txn_from_zipline(backtest)

~/.python/current/lib/python3.10/site-packages/pyfolio/utils.py in ?(backtest)
    151     if backtest.index.tzinfo is None:
    152         backtest.index = backtest.index.tz_localize('UTC')
    153     returns = backtest.returns
    154     raw_positions = []
--> 155     for dt, pos_row in backtest.positions.iteritems():
    156         df = pd.DataFrame(pos_row)
    157         df.index = [dt] * len(df)
    158         raw_positions.append(df)

~/.local/lib/python3.10/site-packages/pandas/core/generic.py in ?(self, name)
   6292             and name not in self._accessors
   6293             and self._info_axis._can_hold_identifiers_and_holds_name(name)
   6294         ):
   6295             return self[name]
-> 6296         return object.__getattribute__(self, name)

AttributeError: 'Series' object has no attribute 'iteritems'

Upon inspecting the type of columns returns ,positions, transactions I am informed that is a ‘Series’ object, and thus not iterable. If I try to set the data in those columns to a DataFrame object prior to running extract_rets_pos_txn_from_zipline(backtest) by running

backtest['returns'] = pd.DataFrame(backtest['returns'])
backtest['positions'] = pd.DataFrame(backtest['positions'])
backtest['transactions'] = pd.DataFrame(backtest['transactions'])

and verify the type, it ends up that no conversion has occurred and those columns are still Series objects.

Further, if I inspect the backtest variable with data viewer after running run_algorithm there is no data in the DataFrame object.

Is there something I am doing incorrectly here?