Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b16c311

Browse files
committed
Fix datetime mess
1 parent 4640237 commit b16c311

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

lib/matplotlib/dates.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ def date2num(d):
419419
return _dt64_to_ordinalf(d)
420420
if not d.size:
421421
return d
422+
if hasattr(d, 'dtype'):
423+
if ((isinstance(d, np.ndarray) and
424+
np.issubdtype(d.dtype, np.datetime64)) or
425+
isinstance(d, np.datetime64)):
426+
return _dt64_to_ordinalf(d)
422427
return _to_ordinalf_np_vectorized(d)
423428

424429

lib/matplotlib/testing/conftest.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,8 @@ def pd():
9191
pd = pytest.importorskip('pandas')
9292
try:
9393
from pandas.plotting import (
94-
register_matplotlib_converters as register)
94+
deregister_matplotlib_converters as deregister)
95+
deregister()
9596
except ImportError:
96-
from pandas.tseries.converter import register
97-
register()
98-
try:
99-
yield pd
100-
finally:
101-
try:
102-
from pandas.plotting import (
103-
deregister_matplotlib_converters as deregister)
104-
except ImportError:
105-
pass
106-
else:
107-
deregister()
97+
pass
98+
return pd

lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5422,6 +5422,18 @@ def test_pandas_bar_align_center(pd):
54225422
fig.canvas.draw()
54235423

54245424

5425+
def test_pandas_data_unpack(pd):
5426+
# smoke test for all these different calling methods.
5427+
dates = [datetime.datetime(2018, 7, i) for i in range(1, 5)]
5428+
values = np.cumsum(np.random.rand(len(dates)))
5429+
df = pd.DataFrame({"dates": dates, "values": values})
5430+
plt.plot(df["dates"].values, df["values"])
5431+
plt.scatter(df["dates"], df["values"])
5432+
plt.plot("dates", "values", data=df)
5433+
plt.scatter(x="dates", y="values", data=df)
5434+
plt.draw()
5435+
5436+
54255437
def test_axis_set_tick_params_labelsize_labelcolor():
54265438
# Tests fix for issue 4346
54275439
axis_1 = plt.subplot()

lib/matplotlib/tests/test_dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ def tz_convert(*args):
618618

619619
def test_dateboxplot_pandas(pd):
620620
# smoke test that this doesn't fail.
621-
data = np.random.rand(5,2)
621+
data = np.random.rand(5, 2)
622622
years = pd.date_range('1/1/2000',
623623
periods=2, freq=pd.DateOffset(years=1)).year
624624
# Does not work

0 commit comments

Comments
 (0)