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

TypeError: cannot astype a timedelta from [timedelta64[ns]] to [int32] #593

Closed
andymancodes opened this issue Jul 4, 2018 · 7 comments
Closed
Milestone

Comments

@andymancodes
Copy link

Hi,

while trying to run: fig = plot_cross_validation_metric(df_cv, metric='mape')

I am getting:

TypeError Traceback (most recent call last)
in ()
----> 1 fig = plot_cross_validation_metric(df_cv, metric='mape')

C:\Program Files\Anaconda3\envs\py35\lib\site-packages\fbprophet\plot.py in plot_cross_validation_metric(df_cv, metric, rolling_window, ax)
462 break
463
--> 464 x_plt = df_none['horizon'].astype('timedelta64[ns]').astype(int) / float(dt_conversions[i])
465 x_plt_h = df_h['horizon'].astype('timedelta64[ns]').astype(int) / float(dt_conversions[i])
466

C:\Program Files\Anaconda3\envs\py35\lib\site-packages\pandas\util_decorators.py in wrapper(*args, **kwargs)
176 else:
177 kwargs[new_arg_name] = new_arg_value
--> 178 return func(*args, **kwargs)
179 return wrapper
180 return _deprecate_kwarg

C:\Program Files\Anaconda3\envs\py35\lib\site-packages\pandas\core\generic.py in astype(self, dtype, copy, errors, **kwargs)
4995 # else, only a single dtype is given
4996 new_data = self._data.astype(dtype=dtype, copy=copy, errors=errors,
-> 4997 **kwargs)
4998 return self._constructor(new_data).finalize(self)
4999

C:\Program Files\Anaconda3\envs\py35\lib\site-packages\pandas\core\internals.py in astype(self, dtype, **kwargs)
3712
3713 def astype(self, dtype, **kwargs):
-> 3714 return self.apply('astype', dtype=dtype, **kwargs)
3715
3716 def convert(self, **kwargs):

C:\Program Files\Anaconda3\envs\py35\lib\site-packages\pandas\core\internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
3579
3580 kwargs['mgr'] = self
-> 3581 applied = getattr(b, f)(**kwargs)
3582 result_blocks = _extend_blocks(applied, result_blocks)
3583

C:\Program Files\Anaconda3\envs\py35\lib\site-packages\pandas\core\internals.py in astype(self, dtype, copy, errors, values, **kwargs)
573 def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
574 return self._astype(dtype, copy=copy, errors=errors, values=values,
--> 575 **kwargs)
576
577 def _astype(self, dtype, copy=False, errors='raise', values=None,

C:\Program Files\Anaconda3\envs\py35\lib\site-packages\pandas\core\internals.py in _astype(self, dtype, copy, errors, values, klass, mgr, **kwargs)
662
663 # _astype_nansafe works fine with 1-d only
--> 664 values = astype_nansafe(values.ravel(), dtype, copy=True)
665 values = values.reshape(self.shape)
666

C:\Program Files\Anaconda3\envs\py35\lib\site-packages\pandas\core\dtypes\cast.py in astype_nansafe(arr, dtype, copy)
694 raise TypeError("cannot astype a timedelta from [{from_dtype}] "
695 "to [{to_dtype}]".format(from_dtype=arr.dtype,
--> 696 to_dtype=dtype))
697
698 elif (np.issubdtype(arr.dtype, np.floating) and

TypeError: cannot astype a timedelta from [timedelta64[ns]] to [int32]

While, df_p = performance_metrics(df_cv) works perfectly fine.

I really need to plot the error.

@FGG100y
Copy link

FGG100y commented Jul 4, 2018

Hi, @andymancodes the exactly same 'TypeError' appeared when I ran the same code. So if you just want to plot the error, maybe you could try to plot it with pd.DataFrame.plot(), it's not as pretty as the 'original ' output figure, but it work. May this would help.

@andymancodes
Copy link
Author

andymancodes commented Jul 4, 2018

@FGGsysu Hi, I am not getting how the evaluation of the model is goining on.

I have set my horizon to 30 days, yet I get

I get:

horizon mape
30 0.247988

  horizon mse rmse mae mape coverage
3 days 01:00:00 1.196251 1.093733 0.808108 0.189526 0.929949
3 days 01:00:00 1.196157 1.093690 0.807951 0.189485 0.929949
3 days 01:00:00 1.192805 1.092156 0.806375 0.189264 0.929949
3 days 01:00:00 1.194557 1.092958 0.807047 0.189117 0.929949
3 days 01:30:00 1.194866 1.093099 0.807151 0.188838 0.929949

How to plot the error now? What does it mean? Any help would be wonderful! Thanks.

@bletham
Copy link
Contributor

bletham commented Jul 10, 2018

This is a bug that shows up on 32-bit systems (see also #591). It was fixed in #577, but the fix hasn't been pushed to PyPI yet. In the meantime you can download and install the current github version.

@bletham
Copy link
Contributor

bletham commented Aug 2, 2018

I'm going to leave this open until we push the next version to pip which will have this fix.

@bletham bletham reopened this Aug 2, 2018
@bletham bletham added this to the v0.4 milestone Dec 3, 2018
@ajoros
Copy link

ajoros commented Dec 11, 2018

I have latest fbprophet package and I am having this issue as well, and I am on 64-bit system. I even manually went into plot.py and modified lines 464 and 465 to use .astype(np.int64) , and still no luck. Error continues saying:
"cannot astype a timedelta from[timedelta64[ns]] to [int32]"

@bletham
Copy link
Contributor

bletham commented Dec 20, 2018

@ajoros we just pushed a new version (0.4) to PyPI that should fix this. Could you re-install fbprophet and check if it works now?

pip uninstall fbprophet
pip install fbprophet --no-cache-dir --no-binary :all:

@bletham
Copy link
Contributor

bletham commented Dec 20, 2018

The fix has been pushed to PyPI so I'll close this, but @ajoros keep me posted so we can make sure it is working in your case.

@bletham bletham closed this as completed Dec 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants