AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime'
Please provide a minimal, self-contained, and reproducible example:
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import argparse
import backtrader as bt
import backtrader.feeds as btfeeds
import pandas
def runstrat():
args = parse_args()
# Create a cerebro entity
cerebro = bt.Cerebro(stdstats=False)
# Add a strategy
cerebro.addstrategy(bt.Strategy)
# Get a pandas dataframe
datapath = ('../../datas/2006-day-001.txt')
# Simulate the header row isn't there if noheaders requested
skiprows = 1 if args.noheaders else 0
header = None if args.noheaders else 0
dataframe = pandas.read_csv(datapath,
skiprows=skiprows,
header=header,
parse_dates=True,
index_col=0)
if not args.noprint:
print('--------------------------------------------------')
print(dataframe)
print('--------------------------------------------------')
# Pass it to the backtrader datafeed and add it to the cerebro
data = bt.feeds.PandasData(dataname=dataframe)
cerebro.adddata(data)
# Run over everything
cerebro.run()
# Plot the result
cerebro.plot(style='bar')
def parse_args():
parser = argparse.ArgumentParser(
description='Pandas test script')
parser.add_argument('--noheaders', action='store_true', default=False,
required=False,
help='Do not use header rows')
parser.add_argument('--noprint', action='store_true', default=False,
help='Print the dataframe')
return parser.parse_args()
if __name__ == '__main__':
runstrat()
File "/home/user/project/venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-7dc148349399>", line 1, in <module>
runfile('/home/user/project/src/workbench/1_3_csv_to_bt.py', wdir='/home/user/project/src/workbench')
File "/home/sergii/.local/share/JetBrains/IntelliJIdea2021.1/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/home/sergii/.local/share/JetBrains/IntelliJIdea2021.1/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/user/project/src/workbench/1_3_csv_to_bt.py", line 73, in <module>
runstrat()
File "/home/user/project/src/workbench/1_3_csv_to_bt.py", line 50, in runstrat
cerebro.run()
File "/home/user/project/venv/lib/python3.9/site-packages/backtrader/cerebro.py", line 1127, in run
runstrat = self.runstrategies(iterstrat)
File "/home/user/project/venv/lib/python3.9/site-packages/backtrader/cerebro.py", line 1212, in runstrategies
data.preload()
File "/home/user/project/venv/lib/python3.9/site-packages/backtrader/feed.py", line 438, in preload
while self.load():
File "/home/user/project/venv/lib/python3.9/site-packages/backtrader/feed.py", line 479, in load
_loadret = self._load()
File "/home/user/project/venv/lib/python3.9/site-packages/backtrader/feeds/pandafeed.py", line 268, in _load
dt = tstamp.to_pydatetime()
AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime'
Problem Description
That is supposed to be fixed by now: https://github.com/quantopian/pyfolio/issues/520 But I still get the same error (with latest deps):
AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime'
Please provide a minimal, self-contained, and reproducible example:
to be copy paste from: https://www.backtrader.com/docu/pandas-datafeed/pandas-datafeed/
data from the file is:
Please provide the full traceback:
Please provide any additional information below:
Versions
same thing. reproducable. https://github.com/quantopian/pyfolio/issues/520 in oct 10 2021. all latest v.: