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

ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' #385

Open
xuanronaldo opened this issue Sep 7, 2020 · 6 comments

Comments

@xuanronaldo
Copy link

xuanronaldo commented Sep 7, 2020

Problem Description

I cathed an exception as the title saying when I call the function "get_clean_factor_and_forward_returns()".But it worked well before.
Please provide a minimal, self-contained, and reproducible example:

factor_return = get_clean_factor_and_forward_returns(multi_index_series, prices)

Please provide the full traceback:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-8d1ecc81ba64> in <module>
----> 1 factor_rice, IC_return_on_equity = alphalens_ic_calculate(fundamentals.financial_indicator.return_on_equity, start_date="2020-01-01", end_date="2020-08-20")

<ipython-input-6-86025a787884> in alphalens_ic_calculate(factor, start_date, end_date)
     30     prices = get_price(stock_list, start_date=start_date, end_date=end_date, fields='close')
     31 
---> 32     factor_return = get_clean_factor_and_forward_returns(multi_index_series, prices, zero_aware=True)
     33     return factor_returns(factor_return).iloc[:, 0].mean(), factor_information_coefficient(factor_return)
     34 

/usr/local/lib/python3.6/site-packages/alphalens/utils.py in get_clean_factor_and_forward_returns(factor, prices, groupby, binning_by_group, quantiles, bins, periods, filter_zscore, groupby_labels, max_loss, zero_aware, cumulative_returns)
    837                                    quantiles=quantiles, bins=bins,
    838                                    binning_by_group=binning_by_group,
--> 839                                    max_loss=max_loss, zero_aware=zero_aware)
    840 
    841     return factor_data

/usr/local/lib/python3.6/site-packages/alphalens/utils.py in get_clean_factor(factor, forward_returns, groupby, binning_by_group, quantiles, bins, groupby_labels, max_loss, zero_aware)
    593     factor_copy = factor.copy()
    594     factor_copy.index = factor_copy.index.rename(['date', 'asset'])
--> 595     factor_copy = factor_copy[np.isfinite(factor_copy)]
    596 
    597     merged_data = forward_returns.copy()

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Please provide any additional information below:

Versions

  • Alphalens version: 0.4.0
  • Python version: 3.6
  • Pandas version: 0.24.2
  • Matplotlib version: 3.1.3
@OnlyAnJ
Copy link

OnlyAnJ commented Sep 9, 2020

same as u...

@xuanronaldo
Copy link
Author

same as u...

I deleted this line,and it works now.

@OnlyAnJ
Copy link

OnlyAnJ commented Sep 9, 2020

same as u...

I deleted this line,and it works now.

so u donot use this function? But how do u get the best factor return

@xuanronaldo
Copy link
Author

same as u...

I deleted this line,and it works now.

so u donot use this function? But how do u get the best factor return

I do call this function! I mean this line "factor_copy = factor_copy[np.isfinite(factor_copy)]" was deleted.U can track this line by ctrl and left mouse button if u use pycharm or some IDE else.

@syejing
Copy link

syejing commented Oct 19, 2020

There is something wrong with your factor data dtype. Try astype ('float ')

@xuanronaldo
Copy link
Author

There is something wrong with your factor data dtype. Try astype ('float ')

Wow!It works.Thank you,dude.

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