Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: If using all scalar values, you must pass an index #1010

Closed
nPokemon opened this issue May 15, 2023 · 7 comments
Closed

ValueError: If using all scalar values, you must pass an index #1010

nPokemon opened this issue May 15, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@nPokemon
Copy link

ValueError Traceback (most recent call last)
in <cell line: 5>()
3
4 # Run ensemble strategy and store the result
----> 5 result = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs,
6 PPO_model_kwargs,
7 DDPG_model_kwargs,

5 frames
/usr/local/lib/python3.10/site-packages/pandas/core/internals/construction.py in _extract_index(data)
643
644 if not indexes and not raw_lengths:
--> 645 raise ValueError("If using all scalar values, you must pass an index")
646
647 if have_series:

ValueError: If using all scalar values, you must pass an index

I have try many way to fix it, but no luck, any one have any idea ?

@YangletLiu YangletLiu added the bug Something isn't working label May 16, 2023
@Sotokama
Copy link

Also facing the same error

@Omar-ALkhateeb
Copy link

same issue

@rendezvoush
Copy link

Yeah, the same issue after "pip install stable-baselines3==2.0.0a5"

======DDPG Validation from: 2021-10-04 to 2022-01-03
======Best Model Retraining from: 2010-01-01 to 2022-01-03
======Trading from: 2022-01-03 to 2022-04-04

Then the following error raised:


ValueError Traceback (most recent call last)
d:\Projects\Python\DQN\FinRL_Ensemble_StockTrading_ICAIF_2020.ipynb Cell 36 in ()
----> 1 df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs,
2 PPO_model_kwargs,
3 DDPG_model_kwargs,
4 timesteps_dict)

File d:\ProgramData\Anaconda3\envs\develop\lib\site-packages\finrl\agents\stablebaselines3\models.py:668, in DRLEnsembleAgent.run_ensemble_strategy(self, A2C_model_kwargs, PPO_model_kwargs, DDPG_model_kwargs, timesteps_dict)
661 print(
662 "======Trading from: ",
663 self.unique_trade_date[i - self.rebalance_window],
664 "to ",
665 self.unique_trade_date[i],
666 )
667 # print("Used Model: ", model_ensemble)
--> 668 last_state_ensemble = self.DRL_prediction(
669 model=model_ensemble,
670 name="ensemble",
671 last_state=last_state_ensemble,
672 iter_num=i,
673 turbulence_threshold=turbulence_threshold,
674 initial=initial,
675 )
676 ############## Trading ends ##############
678 end = time.time()

File d:\ProgramData\Anaconda3\envs\develop\lib\site-packages\finrl\agents\stablebaselines3\models.py:321, in DRLEnsembleAgent.DRL_prediction(self, model, name, last_state, iter_num, turbulence_threshold, initial)
317 if i == (len(trade_data.index.unique()) - 2):
318 # print(env_test.render())
319 last_state = trade_env.render()
--> 321 df_last_state = pd.DataFrame({"last_state": last_state})
322 df_last_state.to_csv(f"results/last_state_{name}_{i}.csv", index=False)
323 return last_state

File d:\ProgramData\Anaconda3\envs\develop\lib\site-packages\pandas\core\frame.py:636, in DataFrame.init(self, data, index, columns, dtype, copy)
630 mgr = self._init_mgr(
631 data, axes={"index": index, "columns": columns}, dtype=dtype, copy=copy
632 )
634 elif isinstance(data, dict):
635 # GH#38939 de facto copy defaults to False only in non-dict cases
--> 636 mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
637 elif isinstance(data, ma.MaskedArray):
638 import numpy.ma.mrecords as mrecords

File d:\ProgramData\Anaconda3\envs\develop\lib\site-packages\pandas\core\internals\construction.py:502, in dict_to_mgr(data, index, columns, dtype, typ, copy)
494 arrays = [
495 x
496 if not hasattr(x, "dtype") or not isinstance(x.dtype, ExtensionDtype)
497 else x.copy()
498 for x in arrays
499 ]
500 # TODO: can we get rid of the dt64tz special case above?
--> 502 return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)

File d:\ProgramData\Anaconda3\envs\develop\lib\site-packages\pandas\core\internals\construction.py:120, in arrays_to_mgr(arrays, columns, index, dtype, verify_integrity, typ, consolidate)
117 if verify_integrity:
118 # figure out the index, if necessary
119 if index is None:
--> 120 index = _extract_index(arrays)
121 else:
122 index = ensure_index(index)

File d:\ProgramData\Anaconda3\envs\develop\lib\site-packages\pandas\core\internals\construction.py:664, in _extract_index(data)
661 raise ValueError("Per-column arrays must each be 1-dimensional")
663 if not indexes and not raw_lengths:
--> 664 raise ValueError("If using all scalar values, you must pass an index")
666 elif have_series:
667 index = union_indexes(indexes)

ValueError: If using all scalar values, you must pass an index

@Aashish-1008
Copy link

Yeah, the same issue after "pip install stable-baselines3==2.0.0a5"

======DDPG Validation from: 2021-10-04 to 2022-01-03
======Best Model Retraining from: 2010-01-01 to 2022-01-03
======Trading from: 2022-01-03 to 2022-04-04

Then the following error raised:

@kilmern
Copy link

kilmern commented Jun 8, 2023

Likewise. Same problem after the suggested fix in #1022

@AkashKarnatak
Copy link
Contributor

AkashKarnatak commented Jun 10, 2023

This commit by stable-baseline3 is the cause of above error. Changing line 319 of finrl/agents/stablebaselines3/models.py from,

last_state = trade_env.render()

to

last_state = trade_env.envs[0].render()

fixes the error.

AkashKarnatak added a commit to AkashKarnatak/FinRL that referenced this issue Jun 10, 2023
@MariamaB
Copy link

MariamaB commented Jun 10, 2023

ValueError: operands could not be broadcast together with shapes (30,) (29,)

Facing the following error when running:

df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs,
PPO_model_kwargs,
DDPG_model_kwargs,
timesteps_dict)

Does anyone know how to fix it?

==================================================================================

Full Error:

ValueError Traceback (most recent call last)
in <cell line: 1>()
----> 1 df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs,
2 PPO_model_kwargs,
3 DDPG_model_kwargs,
4 timesteps_dict)

5 frames
/usr/local/lib/python3.10/dist-packages/finrl/agents/stablebaselines3/models.py in run_ensemble_strategy(self, A2C_model_kwargs, PPO_model_kwargs, DDPG_model_kwargs, timesteps_dict)
424 ],
425 )
--> 426 self.train_env = DummyVecEnv(
427 [
428 lambda: StockTradingEnv(

/usr/local/lib/python3.10/dist-packages/stable_baselines3/common/vec_env/dummy_vec_env.py in init(self, env_fns)
28
29 def init(self, env_fns: List[Callable[[], gym.Env]]):
---> 30 self.envs = [_patch_env(fn()) for fn in env_fns]
31 if len(set([id(env.unwrapped) for env in self.envs])) != len(self.envs):
32 raise ValueError(

/usr/local/lib/python3.10/dist-packages/stable_baselines3/common/vec_env/dummy_vec_env.py in (.0)
28
29 def init(self, env_fns: List[Callable[[], gym.Env]]):
---> 30 self.envs = [_patch_env(fn()) for fn in env_fns]
31 if len(set([id(env.unwrapped) for env in self.envs])) != len(self.envs):
32 raise ValueError(

/usr/local/lib/python3.10/dist-packages/finrl/agents/stablebaselines3/models.py in ()
426 self.train_env = DummyVecEnv(
427 [
--> 428 lambda: StockTradingEnv(
429 df=train,
430 stock_dim=self.stock_dim,

/usr/local/lib/python3.10/dist-packages/finrl/meta/env_stock_trading/env_stocktrading.py in init(self, df, stock_dim, hmax, initial_amount, num_stock_shares, buy_cost_pct, sell_cost_pct, reward_scaling, state_space, action_space, tech_indicator_list, turbulence_threshold, risk_indicator_col, make_plots, print_verbosity, day, initial, previous_state, model_name, mode, iteration)
74 self.iteration = iteration
75 # initalize state
---> 76 self.state = self._initiate_state()
77
78 # initialize reward

/usr/local/lib/python3.10/dist-packages/finrl/meta/env_stock_trading/env_stocktrading.py in _initiate_state(self)
401 # for multiple stock
402 state = (
--> 403 [self.initial_amount]
404 + self.data.close.values.tolist()
405 + self.num_stock_shares

ValueError: operands could not be broadcast together with shapes (30,) (29,)

Patibandha pushed a commit to Patibandha/FinRLv6-23-2023 that referenced this issue Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants