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

Can't run it over 10001 index from csv , then I got the error f"Length of passed values is {len(data)}, " ValueError: Length of passed values is 2, index implies 1. #792

Open
KnudY9 opened this issue Oct 26, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@KnudY9
Copy link

KnudY9 commented Oct 26, 2022

Expected Behavior

I wanna use it over 10000 index with this command(index_col='time', parse_dates=True) without the error ,when I import the csv.

Of cource I should type the code like follow.
df = pd.read_csv("df.csv")

But the date didn't recognize ,when I don't use index_col='time', parse_dates=True.
And the follow error occurred ,when I import the csvfile over 10000 index.There is reproducibility.

Actual Behavior

I read the csv by follow code and csv

code
filename = "raw.csv"
df = pd.read_csv(filename,index_col='time', parse_dates=True)

csvdata example actual data have 10002 index.

time Open High Low Close Volume
2020/1/1 0:01 7187.67 7188.06 7182.2 7184.03 7.248148
2020/1/1 0:02 7184.41 7184.71 7180.26 7182.43 11.68168
2020/1/1 0:03 7183.83 7188.94 7182.49 7185.94 10.02539

Line 10001 does not give an error.
But an error occurs when the csv reaches 10002 rows.
This error occurred when reading CSV with the following command.

target code
index_col='time', parse_dates=True

Steps to Reproduce

C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\backtesting\_plotting.py:122: UserWarning: Data contains too many candlesticks to plot; downsampling to '1T'. See `Backtest.plot(resample=...)`
  warnings.warn(f"Data contains too many candlesticks to plot; downsampling to {freq!r}. "
Traceback (most recent call last):
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\groupby\generic.py", line 261, in aggregate
    func, *args, engine=engine, engine_kwargs=engine_kwargs, **kwargs
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\groupby\groupby.py", line 1085, in _python_agg_general
    result, counts = self.grouper.agg_series(obj, f)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\groupby\ops.py", line 904, in agg_series
    return grouper.get_result()
  File "pandas\_libs\reduction.pyx", line 164, in pandas._libs.reduction.SeriesBinGrouper.get_result
  File "pandas\_libs\reduction.pyx", line 76, in pandas._libs.reduction._BaseGrouper._apply_to_group
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\groupby\groupby.py", line 1062, in <lambda>
    f = lambda x: func(x, *args, **kwargs)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\backtesting\_plotting.py", line 147, in f
    mean_time = int(bars.loc[s.index].view(int).mean())
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\series.py", line 668, in view
    self._values.view(dtype), index=self.index
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\series.py", line 314, in __init__
    f"Length of passed values is {len(data)}, "
ValueError: Length of passed values is 2, index implies 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "1.py", line 183, in <module>
    bt.plot() 
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\backtesting\backtesting.py", line 1609, in plot
    open_browser=open_browser)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\backtesting\_plotting.py", line 204, in plot
    resample, df, indicators, equity_data, trades)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\backtesting\_plotting.py", line 158, in _maybe_resample_data
    ExitBar=_group_trades('ExitTime'),
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\resample.py", line 288, in aggregate
    result, how = self._aggregate(func, *args, **kwargs)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\base.py", line 416, in _aggregate
    result = _agg(arg, _agg_1dim)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\base.py", line 383, in _agg
    result[fname] = func(fname, agg_how)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\base.py", line 367, in _agg_1dim
    return colg.aggregate(how)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\groupby\generic.py", line 267, in aggregate
    result = self._aggregate_named(func, *args, **kwargs)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\groupby\generic.py", line 480, in _aggregate_named
    output = func(group, *args, **kwargs)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\backtesting\_plotting.py", line 147, in f
    mean_time = int(bars.loc[s.index].view(int).mean())
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\series.py", line 668, in view
    self._values.view(dtype), index=self.index
  File "C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\series.py", line 314, in __init__
    f"Length of passed values is {len(data)}, "
ValueError: Length of passed values is 2, index implies 1.

Additional info

  • Backtesting version: 0.3.3
  • My python 3.6.8
  • win10
@KnudY9 KnudY9 changed the title import > 10001 index from csv , then I got the error f"Length of passed values is {len(data)}, " ValueError: Length of passed values is 2, index implies 1. Can't run over 10001 index from csv , then I got the error f"Length of passed values is {len(data)}, " ValueError: Length of passed values is 2, index implies 1. Nov 4, 2022
@KnudY9 KnudY9 changed the title Can't run over 10001 index from csv , then I got the error f"Length of passed values is {len(data)}, " ValueError: Length of passed values is 2, index implies 1. Can't run it over 10001 index from csv , then I got the error f"Length of passed values is {len(data)}, " ValueError: Length of passed values is 2, index implies 1. Nov 4, 2022
@KnudY9
Copy link
Author

KnudY9 commented Nov 26, 2022

anybody here_?

@kernc
Copy link
Owner

kernc commented Dec 8, 2022

Can you share some minimal example code to reproduce the issue?

@muratokutucu
Copy link

Hello, I have the same issue. Any solution please?

@kernc kernc added the bug Something isn't working label Aug 24, 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

3 participants