You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "report.py", line 10, in <module>
data.plot.area()
File ".venv/lib/python3.10/site-packages/pandas/plotting/_core.py", line 1546, in areareturnself(kind="area", x=x, y=y, stacked=stacked, **kwargs)
File ".venv/lib/python3.10/site-packages/pandas/plotting/_core.py", line 981, in __call__return plot_backend.plot(data, kind=kind, **kwargs)
File ".venv/lib/python3.10/site-packages/pandas/plotting/_matplotlib/__init__.py", line 71, in plot
plot_obj.generate()
File ".venv/lib/python3.10/site-packages/pandas/plotting/_matplotlib/core.py", line 449, in generateself._make_plot()
File ".venv/lib/python3.10/site-packages/pandas/plotting/_matplotlib/core.py", line 1383, in _make_plot
newlines = plotf(
File ".venv/lib/python3.10/site-packages/pandas/plotting/_matplotlib/core.py", line 1557, in _plot
y_values =cls._get_stacked_values(ax, stacking_id, y, kwds["label"])
File ".venv/lib/python3.10/site-packages/pandas/plotting/_matplotlib/core.py", line 1461, in _get_stacked_valuesif (values >=0).all():
numpy.core._exceptions._UFuncInputCastingError: Cannot cast ufunc 'greater_equal' input 0 from dtype('<m8[ns]') to dtype('<m8') with casting rule 'same_kind'
Issue Description
Creating an area plot of timedeltas fails _UFuncInputCastingError on the main branch. The line plot works fine data.plot.line().
In the latest version of pandas, the line-plot also works fine but the area plot throws:
report.py:10: FutureWarning: The behavior of fillna with timedelta64[ns] dtype and an incompatible value (<class 'int'>) is deprecated. In a future version, this will cast to a common dtype (usually object) instead of raising, matching the behavior of other dtypes.
data.plot.area()
Traceback (most recent call last):
File "report.py", line 10, in <module>
data.plot.area()
File ".venv/lib/python3.10/site-packages/pandas/plotting/_core.py", line 1557, in areareturnself(kind="area", x=x, y=y, **kwargs)
File ".venv/lib/python3.10/site-packages/pandas/plotting/_core.py", line 1000, in __call__return plot_backend.plot(data, kind=kind, **kwargs)
File ".venv/lib/python3.10/site-packages/pandas/plotting/_matplotlib/__init__.py", line 70, in plot
plot_obj =PLOT_CLASSES[kind](data, **kwargs)
File ".venv/lib/python3.10/site-packages/pandas/plotting/_matplotlib/core.py", line 1529, in __init__
data = data.fillna(value=0)
File ".venv/lib/python3.10/site-packages/pandas/util/_decorators.py", line 331, in wrapperreturn func(*args, **kwargs)
File ".venv/lib/python3.10/site-packages/pandas/core/frame.py", line 5635, in fillnareturnsuper().fillna(
File ".venv/lib/python3.10/site-packages/pandas/core/generic.py", line 6922, in fillna
new_data =self._mgr.fillna(
File ".venv/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 443, in fillnareturnself.apply(
File "/.venv/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 352, in apply
applied =getattr(b, f)(**kwargs)
File ".venv/lib/python3.10/site-packages/pandas/core/internals/blocks.py", line 1566, in fillna
res_values =self.values.fillna(value, limit=limit)
File ".venv/lib/python3.10/site-packages/pandas/core/arrays/_mixins.py", line 346, in fillnaself._validate_setitem_value(value)
File ".venv/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py", line 789, in _validate_setitem_valuereturnself._validate_scalar(value, allow_listlike=True)
File "venv/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py", line 690, in _validate_scalarraiseTypeError(msg)
TypeError: value should be a 'Timedelta', 'NaT', or array of those. Got 'int' instead.
Uh oh!
There was an error while loading. Please reload this page.
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Creating an area plot of timedeltas fails
_UFuncInputCastingError
on the main branch. The line plot works finedata.plot.line()
.In the latest version of pandas, the line-plot also works fine but the area plot throws:
This seems to be resolved by #48103 .
Expected Behavior
Plot an area plot, similar to the line plot.
Workaround (from https://stackoverflow.com/questions/23543909/plotting-pandas-timedelta):
Convert the
timedelta
into a numeric value by dividing by a fixedtimedelta
of your choice:data = data/pd.Timedelta(hours=1)
Installed Versions
The text was updated successfully, but these errors were encountered: