Comments (15)
I'm not sure what the precise cause of this is, but I think this could be an issue with how matplotlib handles the the numpy datetime objects. The code below replicates the error for me.
date_range = pd.date_range("01-01-2017", "31-12-2017")
df = pd.DataFrame({"ds":date_range , "upper": [2 for _ in range(len(date_range))], "lower": [1 for _ in range(len(date_range))]})
fig, axes = plt.subplots(figsize=(14,5))
axes.fill_between(df.ds, y1=df.lower, y2=df.upper)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-64-de8ba625d7d6> in <module>()
4
5 fig, axes = plt.subplots(figsize=(14,5))
----> 6 ax.fill_between(df.ds, y1=df.lower, y2=df.upper)
/app/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1708 warnings.warn(msg % (label_namer, func.__name__),
1709 RuntimeWarning, stacklevel=2)
-> 1710 return func(ax, *args, **kwargs)
1711 pre_doc = inner.__doc__
1712 if pre_doc is None:
/app/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in fill_between(self, x, y1, y2, where, interpolate, step, **kwargs)
4830
4831 # Convert the arrays so we can work with them
-> 4832 x = ma.masked_invalid(self.convert_xunits(x))
4833 y1 = ma.masked_invalid(self.convert_yunits(y1))
4834 y2 = ma.masked_invalid(self.convert_yunits(y2))
/app/anaconda3/lib/python3.6/site-packages/numpy/ma/core.py in masked_invalid(a, copy)
2386 cls = type(a)
2387 else:
-> 2388 condition = ~(np.isfinite(a))
2389 cls = MaskedArray
2390 result = a.view(cls)
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''
Try the following work around, which converts the numpy datetime64[ns] type to an array of python datetime.datetime objects, which I think resolves the issue.
date_range = pd.date_range("01-01-2017", "31-12-2017")
df = pd.DataFrame({"ds":date_range , "upper": [2 for _ in range(len(date_range))], "lower": [1 for _ in range(len(date_range))]})
fig, axes = plt.subplots(figsize=(14,5))
axes.fill_between(df.ds.dt.to_pydatetime(), y1=df.lower, y2=df.upper)
from prophet.
Could you attach the fcst
dataframe that produces this issue so I can try to replicate it?
from prophet.
@bletham, I am using pandas version '0.24.2' and following the snippet of my code which still results in the error TypeError: ufunc 'isfinite' not supported for the input types
df = pd.read_csv('Filename.csv') \ df['Date'] = df['Date'].astype('datetime64') \ df['Date'] = df.Date.dt.to_pydatetime() \ result = seasonal_decompose(df['ACURA'], model='multiplicative', freq=12)
Any help is greatly appreciated.
from prophet.
how does your ds
look?
i get the same error when i try to load not a single day per entry, but a higher resolution as 2017-02-27T12:38:03Z
edit: this is some numpy-issue... http://stackoverflow.com/questions/23808327/unexpected-exception-in-numpy-isfinite
from prophet.
This is the head of my dataframe:
0 2015-10-01 82
1 2015-10-02 76
2 2015-10-03 76
3 2015-10-04 65
4 2015-10-05 62
Using %Y-%m-%d datetime format
from prophet.
This problem came from python 2. The plots worked on python 3.
from prophet.
This should work with Python 2 also, do you have a traceback that shows what line in Prophet the error is coming from?
from prophet.
(i am running python3)
TypeError Traceback (most recent call last)
<ipython-input-270-34f56bf61ffc> in <module>()
----> 1 m.plot_components(forecast)
ipython/venv/lib/python3.6/site-packages/fbprophet/forecaster.py in plot_components(self, fcst, uncertainty)
666 ax.fill_between(
667 fcst['ds'].values, fcst['trend_lower'], fcst['trend_upper'],
--> 668 color=forecast_color, alpha=0.2)
669 ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
670 ax.xaxis.set_major_locator(MaxNLocator(nbins=7))
ipython/venv/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1890 warnings.warn(msg % (label_namer, func.__name__),
1891 RuntimeWarning, stacklevel=2)
-> 1892 return func(ax, *args, **kwargs)
1893 pre_doc = inner.__doc__
1894 if pre_doc is None:
ipython/venv/lib/python3.6/site-packages/matplotlib/axes/_axes.py in fill_between(self, x, y1, y2, where, interpolate, step, **kwargs)
4770
4771 # Convert the arrays so we can work with them
-> 4772 x = ma.masked_invalid(self.convert_xunits(x))
4773 y1 = ma.masked_invalid(self.convert_yunits(y1))
4774 y2 = ma.masked_invalid(self.convert_yunits(y2))
ipython/venv/lib/python3.6/site-packages/numpy/ma/core.py in masked_invalid(a, copy)
2343 cls = type(a)
2344 else:
-> 2345 condition = ~(np.isfinite(a))
2346 cls = MaskedArray
2347 result = a.view(cls)
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''
from prophet.
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
ds yhat yhat_lower yhat_upper
2332 2018-02-23 15:32:19 -2709.268537 -1.956903e+06 1.804301e+06
2333 2018-02-24 15:32:19 -2716.817938 -1.967014e+06 1.814499e+06
2334 2018-02-25 15:32:19 -2724.358051 -1.977111e+06 1.821530e+06
2335 2018-02-26 15:32:19 -2732.206147 -1.986902e+06 1.830387e+06
2336 2018-02-27 15:32:19 -2739.408457 -1.993734e+06 1.840862e+06
is that enough? otherwise i will have to make my jupyter notebook read new data :-)
from prophet.
I thought it might be the timestamps but I made a dataset with similar timestamps and couldn't replicate the issue with it (dataset attached). If you just send input data that produces this issue I could hopefully replicate it and fix it from that. Thanks!
from prophet.
sorry, but i dont have the dataset anymore. i have been playing around with an jupyter notebook and fetching data from a TSDB at the time :-/
from prophet.
@MatiasSanchezCabrera do you still have a dataset that produces this issue that you could share?
from prophet.
I wasn't able to replicate this but that aspect of the plotting has been pretty thoroughly overhauled so I don't expect to see this issue anymore.
from prophet.
@JKPoynter Thanks for the fix on this. This has now been included in v0.2.1 which was just pushed to PyPI.
from prophet.
@monika0603 it looks like the seasonal_decompose
function is from statsmodel, not this package. Your best bet will be to ask on their issue tracker (https://github.com/statsmodels/statsmodels)
from prophet.
Related Issues (20)
- error in pip install pystan, cython was installed, does anyone know how to solve it?
- Fit params for kwargs
- fbprophet installing error HOT 1
- RuntimeError: Error during optimization: console log output: dyld[10867]: Symbol not found
- pip install guardrails getting this error HOT 2
- Prophet Training Speed: Intel vs Apple M1/M2 HOT 2
- RuntimeError: Error during optimization! HOT 3
- fbprophet install error fix
- BUG - Cannot predict on using logistic -> All-NaN slice encountered HOT 1
- Add interactions to weekly/daily periods for hourly univariate time series data
- [BUG] Zero Division in diagnostics.performance_metrics() causing failed assertion
- Using prophet 1.1.4 (python), is it possible to get "adapt_delta" passed down to stan as part of the "fit" call?
- I am a beginner and I do not know How to solve this Error HOT 5
- Loading META Prophet model gives a tz, datetime error HOT 1
- select_()` was deprecated in dplyr 0.7.0
- How to add some new E-commerce holidays for one country HOT 2
- KeyError: 'k' missing
- prophet uses deprecated numpy np.float/int aliases HOT 1
- Covid One Off Holidays HOT 1
- Do we have alternative library for prophet written by java?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prophet.