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

Still seeing the same issue on TypeError for barset.df #12

Open
sunjiawen opened this issue Jan 31, 2019 · 5 comments
Open

Still seeing the same issue on TypeError for barset.df #12

sunjiawen opened this issue Jan 31, 2019 · 5 comments
Assignees

Comments

@sunjiawen
Copy link

File "/app/samplealgo/algo.py", line 50, in _get_prices
2019-01-31T17:02:13.116398+00:00 app[worker.1]: return barset.df
2019-01-31T17:02:13.116402+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_trade_api/entity.py", line 102, in df
2019-01-31T17:02:13.116581+00:00 app[worker.1]: df = bars.df.copy()
2019-01-31T17:02:13.116585+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_trade_api/entity.py", line 84, in df
2019-01-31T17:02:13.116746+00:00 app[worker.1]: df.index * 1e9, utc=True,
2019-01-31T17:02:13.116750+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/pandas/core/ops.py", line 176, in invalid_op
2019-01-31T17:02:13.116959+00:00 app[worker.1]: "{typ}".format(name=name, typ=type(self).name))
2019-01-31T17:02:13.116983+00:00 app[worker.1]: TypeError: cannot perform mul with this index type: Index

@sunjiawen
Copy link
Author

Running locally and see this error:

File "main.py", line 5, in
algo.main()
File "/Users/jiawensun/Alpaca/samplealgo/algo.py", line 222, in main
price_df = prices(Universe)
File "/Users/jiawensun/Alpaca/samplealgo/algo.py", line 72, in prices
return _get_prices(symbols, end_dt)
File "/Users/jiawensun/Alpaca/samplealgo/algo.py", line 59, in _get_prices
return barset.df
File "/usr/local/lib/python3.7/site-packages/alpaca_trade_api/entity.py", line 107, in df
df = bars.df.copy()
File "/usr/local/lib/python3.7/site-packages/alpaca_trade_api/entity.py", line 85, in df
df.index * 1e9, utc=True,
File "/usr/local/lib/python3.7/site-packages/pandas/core/tools/datetimes.py", line 603, in to_datetime
result = convert_listlike(arg, box, format)
File "/usr/local/lib/python3.7/site-packages/pandas/core/tools/datetimes.py", line 223, in _convert_listlike_datetimes
arg, _ = maybe_convert_dtype(arg, copy=False)
File "/usr/local/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py", line 1914, in maybe_convert_dtype
data = data.astype(_NS_DTYPE)
File "/usr/local/lib/python3.7/site-packages/pandas/core/indexes/numeric.py", line 330, in astype
raise TypeError(msg)
TypeError: Cannot convert Float64Index to dtype datetime64[ns]; integer values are required for conversion

@sunjiawen
Copy link
Author

I fixed it myself by converting it to int64

        if not df.empty:
            df.index = pd.to_datetime(
                (df.index * 1e9).astype('int64'), utc=True,
            ).tz_convert(NY)

@tylerfloyd
Copy link

I fixed it myself by converting it to int64

        if not df.empty:
            df.index = pd.to_datetime(
                (df.index * 1e9).astype('int64'), utc=True,
            ).tz_convert(NY)

Where did you put this block of code? I am running into the same issue.

@cujo0072
Copy link

cujo0072 commented Feb 5, 2019

in the enity.py file. Make sure your running the latest alpaca-trade-api (0.24) on line 84:
if not df.empty:
df.index = pd.to_datetime(
(df.index * 1e9).astype('int64'), utc=True,
).tz_convert(NY)
else:
df.index = pd.to_datetime(
df.index, utc=True
)

@davecramer
Copy link

Use api version 0.26

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

5 participants