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

Iterator operand 0 dtype could not be cast from dtype('<M8[us]') to dtype('<M8[D]') according to the rule 'safe' #339

Closed
PeterSikuda opened this issue May 7, 2019 · 3 comments

Comments

@PeterSikuda
Copy link

PeterSikuda commented May 7, 2019

Problem Description

I am trying to process factor, pricing data for alphalens analysis, but got this error.

TypeError: Iterator operand 0 dtype could not be cast from dtype('<M8[us]') to dtype('<M8[D]') according to the rule 'safe'

al.utils.get_clean_factor_and_forward_returns(
        factor=df['sentiment'],
        prices=pricing,
        periods=(1,3))
pricing.index

DatetimeIndex(['2018-05-31', '2018-06-01', '2018-06-02', '2018-06-03',
'2018-06-04', '2018-06-05', '2018-06-06', '2018-06-07',
'2018-06-08', '2018-06-09',
...
'2019-03-22', '2019-03-23', '2019-03-24', '2019-03-25',
'2019-03-26', '2019-03-27', '2019-03-28', '2019-03-29',
'2019-03-30', '2019-03-31'],
dtype='datetime64[ns]', length=305, freq=None)

df.index.levels[0]

DatetimeIndex(['2018-05-31', '2018-06-01', '2018-06-02', '2018-06-03',
'2018-06-04', '2018-06-05', '2018-06-06', '2018-06-07',
'2018-06-08', '2018-06-09',
...
'2019-03-22', '2019-03-23', '2019-03-24', '2019-03-25',
'2019-03-26', '2019-03-27', '2019-03-28', '2019-03-29',
'2019-03-30', '2019-03-31'],
dtype='datetime64[ns]', name='datetime', length=305, freq=None)

Also tried:

pricing.index = pricing.index.values.astype('datetime64[D]')
df.index.levels[0].values.astype('datetime64[D]')

but didn't help.

Versions

  • Alphalens version: 0.3.2
  • Python version: 3.6
  • Pandas version: 0.24.1
  • Matplotlib version: 2.1.0
@luca-s
Copy link
Collaborator

luca-s commented May 8, 2019

If you could upgrade Alphalens to version 0.3.6 that should fix the issue.

@luca-s
Copy link
Collaborator

luca-s commented May 8, 2019

Just to give more background information: we improved Alphalens compatibility with recent pandas versions (tested up to pandas 0.23.4) in one of the latest Alphalens releases. So it should worth upgrading Alphalens and see how it works.

@PeterSikuda
Copy link
Author

thanks. upgrading to version 0.3.6 fixed the issue.

@luca-s luca-s closed this as completed May 9, 2019
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

2 participants