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

OverflowError: cannot convert float infinity to integer #6

Closed
aa-gamJain opened this issue Aug 3, 2019 · 22 comments
Closed

OverflowError: cannot convert float infinity to integer #6

aa-gamJain opened this issue Aug 3, 2019 · 22 comments

Comments

@aa-gamJain
Copy link

test.xlsx
Below two functions are not working in attached data.

  1. qs.plots.snapshot()
  2. qs.reports.full()

Function returns:
OverflowError: cannot convert float infinity to integer

@ranaroussi
Copy link
Owner

Try cleaning up your data before using it, using:

import numpy as np
import quantstats as qs

your_data = your_data.replace([np.inf, -np.inf, -0], 0)

qs.plots.snapshot(your_data)

Let me know if that works out 😉

@aa-gamJain
Copy link
Author

aa-gamJain commented Aug 3, 2019

Not worked.

There are no infinity values in the data

@ranaroussi
Copy link
Owner

Can you re-upload your data? I seem to be corrupted...

@aa-gamJain
Copy link
Author

@ranaroussi
Copy link
Owner

Upgrade to the latest version and try again.

$ pip install quantstats -U --no-cache-dir

@aa-gamJain
Copy link
Author

Still same error

@ranaroussi
Copy link
Owner

ranaroussi commented Aug 3, 2019

Running this code works ok for me:

import pandas as pd
import quantstats as qs

df = pd.read_csv('test.csv', names=['date', 'price'], 
                 index_col=['date'], parse_dates=['date'])[100:]
df['returns'] = df['price'].pct_change().fillna(0)

qs.plots.snapshot(df['returns'])

Result is below:
Unknown

@ranaroussi
Copy link
Owner

If you're using jupyter - try reloading retarting the notebook kernel and import the libraries again to make sure you're using the latest version.

@aa-gamJain
Copy link
Author

Not working in: qs.reports.full()

@ranaroussi
Copy link
Owner

Can you post the entire code you're using? I've tested every method and eveything works.

@aa-gamJain
Copy link
Author

`df = pd.read_csv('test.csv', names=['date', 'price'], index_col=['date'], parse_dates=['date'])[100:]
df['returns'] = df['price'].pct_change().fillna(0)

qs.plots.snapshot(df['returns']) # Works

qs.reports.full(df['returns'] , "SPY") # return error`

ValueError: cannot convert float NaN to integer

@aa-gamJain
Copy link
Author

image

Can you share which version of pandas and numpy are you using?

If you check the picture it won't able to plot Rolling Beta to Benchmark

@ranaroussi
Copy link
Owner

ranaroussi commented Aug 3, 2019

Upgrade to the latest version and try again. Again :)

$ pip install quantstats -U --no-cache-dir

@aa-gamJain
Copy link
Author

aa-gamJain commented Aug 3, 2019

I upgraded again. Restart the jupyter notebook and still the same error.

By error it looks there is some error in plot_rolling_beta function

@aa-gamJain
Copy link
Author

mmin = min([-100, int(beta.min()*100)])
In this line beta.min() returning NaN so it cannot convert NaN to integer. Can you please check?

@ranaroussi
Copy link
Owner

ranaroussi commented Aug 3, 2019 via email

@aa-gamJain
Copy link
Author

I run the pip install quantstats -U --no-cache-dir

still its 0.0.19

@aa-gamJain
Copy link
Author

I fixed it out. Thank you very much :)

@ranaroussi
Copy link
Owner

👍🏻

@ranaroussi ranaroussi reopened this Aug 3, 2019
@ranaroussi
Copy link
Owner

👍🏻

@Onepamopa
Copy link

BTW, the error still occurs, I'm investigating further and will provide more details when I have them.

@chenyispace
Copy link

encountering the same issue. Can kindly explain how you resolved it? thanks

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

4 participants