Skip to content

Commit 5b9b29d

Browse files
committed
BUG: Handle iterable of arrays in convert
DatetimeConverter.convert can take an array or iterable of arrays. Fixed the converter to detect which case we're in and then re-use the existing logic.
1 parent 8daf9a7 commit 5b9b29d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pandas/plotting/_converter.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
is_integer_dtype,
1717
is_float_dtype,
1818
is_datetime64_ns_dtype,
19-
is_period_arraylike)
19+
is_period_arraylike,
20+
is_list_like
21+
)
2022

2123
from pandas.compat import lrange
2224
import pandas.compat as compat
@@ -178,6 +180,16 @@ class DatetimeConverter(dates.DateConverter):
178180

179181
@staticmethod
180182
def convert(values, unit, axis):
183+
# values might be a 1-d array, or a list-like of arrays.
184+
if is_list_like(values) and is_list_like(values[0]):
185+
values = [DatetimeConverter._convert_1d(v, unit, axis)
186+
for v in values]
187+
else:
188+
values = DatetimeConverter._convert_1d(values, unit, axis)
189+
return values
190+
191+
@staticmethod
192+
def _convert_1d(values, unit, axis):
181193
def try_parse(values):
182194
try:
183195
return _dt_to_float_ordinal(tools.to_datetime(values))

pandas/tests/plotting/test_datetimelike.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,15 @@ def test_timedelta_plot(self):
13321332
s = Series(np.random.randn(len(index)), index)
13331333
_check_plot_works(s.plot)
13341334

1335+
def test_hist(self):
1336+
# https://github.com/matplotlib/matplotlib/issues/8459
1337+
rng = date_range('1/1/2011', periods=10, freq='H')
1338+
1339+
x = rng
1340+
w1 = np.arange(0, 1, .1)
1341+
w2 = np.arange(0, 1, .1)[::-1]
1342+
self.plt.hist([x, x], weights=[w1, w2])
1343+
13351344

13361345
def _check_plot_works(f, freq=None, series=None, *args, **kwargs):
13371346
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)