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: arrays must be the same length #6

Open
peter-ch opened this issue May 24, 2021 · 2 comments
Open

ValueError: arrays must be the same length #6

peter-ch opened this issue May 24, 2021 · 2 comments

Comments

@peter-ch
Copy link

I'm running the demo notebook unmodified on Ubuntu 20.04 machine with one GPU, everything is pip installed properly, but I keep getting this error below no matter what I do. It works in Colab but not locally. Why? How can I fix this?

| load data: .//StockTradingEnv_trading_data.df
| YahooDownloader: finish processing date list
| GPU id: 0, cwd: ./AgentPPO/StockTradingEnv-v2_0
Loaded act: ./AgentPPO/StockTradingEnv-v2_0

ValueError Traceback (most recent call last)
in
6 args.init_before_training()
7
----> 8 prediction = args.env.trade_prediction(args, torch)

~/Dropbox/Code/work/stocks_boredhumans/Elegant-FinRL/elegant_finrl/env.py in trade_prediction(self, args, _torch)
266 # print(len(self.date_list))
267 # print(self.date_list)
--> 268 df_account_value = pd.DataFrame({'date':self.date_list,'account_value':episode_returns})
269 return df_account_value
270

/usr/local/lib/python3.8/dist-packages/pandas/core/frame.py in init(self, data, index, columns, dtype, copy)
527
528 elif isinstance(data, dict):
--> 529 mgr = init_dict(data, index, columns, dtype=dtype)
530 elif isinstance(data, ma.MaskedArray):
531 import numpy.ma.mrecords as mrecords

/usr/local/lib/python3.8/dist-packages/pandas/core/internals/construction.py in init_dict(data, index, columns, dtype)
285 arr if not is_datetime64tz_dtype(arr) else arr.copy() for arr in arrays
286 ]
--> 287 return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
288
289

/usr/local/lib/python3.8/dist-packages/pandas/core/internals/construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype, verify_integrity)
78 # figure out the index, if necessary
79 if index is None:
---> 80 index = extract_index(arrays)
81 else:
82 index = ensure_index(index)

/usr/local/lib/python3.8/dist-packages/pandas/core/internals/construction.py in extract_index(data)
399 lengths = list(set(raw_lengths))
400 if len(lengths) > 1:
--> 401 raise ValueError("arrays must all be same length")
402
403 if have_dicts:

ValueError: arrays must all be same length

@jhmenke
Copy link

jhmenke commented May 29, 2021

For a temporary fix you can use self.date_list[1:] since the first entry is wrong. The Yahoo Downloader can return dates previous to the start date.

A better fix is to add two lines after the first one in env.py:

print("| YahooDownloader: finish processing date list"). # this one exists already
raw_df["date"] = pd.to_datetime(raw_df.date)
raw_df = raw_df[raw_df.date >= datetime.strptime(start, "%Y-%m-%d")]

@SteamedGit
Copy link

I'm going to turn this into a pull request. Credit to @jhmenke.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants