That this worked before seems fortuitous, but not consistent with other dates. What units are 10 supposed to be in this example? I’m not clear on what pandas has for a timedelta, but that’s what we would expect for a date using other Datetimes with bar.
Open to the idea that this behaviour still needs to be changed. I got talked into the current implementation, but maybe it’s wrong.
? Are you sure that worked v3.0.2 w/o an error? It fails for me back to v2.2.3 (which is where I quit, because I would have to recompile)
Traceback (most recent call last):
File "testPandas.py", line 10, in <module>
ax.bar(df['date'], df['value'], width=10,align='center')
File "/Users/jklymak/matplotlib/lib/matplotlib/__init__.py", line 1810, in inner
return func(ax, *args, **kwargs)
File "/Users/jklymak/matplotlib/lib/matplotlib/axes/_axes.py", line 2277, in bar
left = x - width / 2
TypeError: ufunc subtract cannot use operands with types dtype('<M8[ns]') and dtype('float64')
@jklymak actually that specific example doesn't work on 3.0.2 - what did work then but fails now is slightly more complicated - I was grouping by my date column. I guess because the tpye of the grouped column is a pandas.core.indexes.datetimes.DatetimeIndex and perhaps that supports addition with a unit-less width?
Given that the error is ValueError: Cannot add integral value to Timestamp without freq. I think pandas should really change that to a TypeError, but, see #13187 for a quick fix that seems to work.
Activity
jklymak commented on Jan 14, 2019
That this worked before seems fortuitous, but not consistent with other dates. What units are 10 supposed to be in this example? I’m not clear on what pandas has for a timedelta, but that’s what we would expect for a date using other Datetimes with bar.
Open to the idea that this behaviour still needs to be changed. I got talked into the current implementation, but maybe it’s wrong.
jklymak commented on Jan 14, 2019
Crossref #12903
jklymak commented on Jan 14, 2019
? Are you sure that worked v3.0.2 w/o an error? It fails for me back to v2.2.3 (which is where I quit, because I would have to recompile)
Traceback (most recent call last): File "testPandas.py", line 10, in <module> ax.bar(df['date'], df['value'], width=10,align='center') File "/Users/jklymak/matplotlib/lib/matplotlib/__init__.py", line 1810, in inner return func(ax, *args, **kwargs) File "/Users/jklymak/matplotlib/lib/matplotlib/axes/_axes.py", line 2277, in bar left = x - width / 2 TypeError: ufunc subtract cannot use operands with types dtype('<M8[ns]') and dtype('float64')david-waterworth commented on Jan 15, 2019
@jklymak actually that specific example doesn't work on 3.0.2 - what did work then but fails now is slightly more complicated - I was grouping by my date column. I guess because the tpye of the grouped column is a pandas.core.indexes.datetimes.DatetimeIndex and perhaps that supports addition with a unit-less width?
import pandas as pd import matplotlib.pyplot as plt fig = plt.figure(figsize=(20,10)); ax = fig.gca(); df = pd.DataFrame({'year':[2018,2018,2018],'month':[1,2,3], 'day':[1,2,3], 'value':[1,3,2]}) df['date'] = pd.to_datetime(df[['year', 'month', 'day']]) monthly = df[['date','value']].groupby(['date']).sum() dates = monthly.index colours = ['lightslategray','lightsteelblue','lightslategray'] forecast = monthly['value'] baseline = monthly['value'] ax.bar(dates, forecast, color = colours, width=10,align='center') ax.plot(dates, baseline, color = 'orange',lw=4)jklymak commented on Jan 15, 2019
Given that the error is ValueError: Cannot add integral value to Timestamp without freq. I think pandas should really change that to a TypeError, but, see #13187 for a quick fix that seems to work.
jklymak commented on Jan 15, 2019
I suspect you really should be passing something more meaningful in as the width there, but since pandas allows it, we shouldn't break it.
david-waterworth commented on Jan 15, 2019
Yeah i agree - it's confusing that it appears to work in one case but not the other. Thanks
jklymak commented on Jan 15, 2019
Lets leave open until we get our fix in. #13187 will automatically close it...