Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd87ac91

Browse files
committed
Fix datetime mess
1 parent95e4e52 commitd87ac91

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

‎lib/matplotlib/dates.py‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,19 +411,24 @@ def date2num(d):
411411
For details see the module docstring.
412412
"""
413413

414-
ifhasattr(d,"values"):
415-
# this unpacks pandas series or dataframes...
416-
d=d.values
417-
418-
if ((isinstance(d,np.ndarray)andnp.issubdtype(d.dtype,np.datetime64))
419-
orisinstance(d,np.datetime64)):
420-
return_dt64_to_ordinalf(d)
421414
ifnotcbook.iterable(d):
415+
ifhasattr(d,'dtype'):
416+
if (np.issubdtype(d.dtype,np.datetime64)or
417+
isinstance(d,np.datetime64)):
418+
return_dt64_to_ordinalf(d)
422419
return_to_ordinalf(d)
423420
else:
424421
d=np.asarray(d)
422+
# note that this unpacks anything that has a numpy array in it
423+
# and just returns the array. So this strips the array out of
424+
# a pandas series object, for instance.
425425
ifnotd.size:
426426
returnd
427+
ifhasattr(d,'dtype'):
428+
if ((isinstance(d,np.ndarray)and
429+
np.issubdtype(d.dtype,np.datetime64))or
430+
isinstance(d,np.datetime64)):
431+
return_dt64_to_ordinalf(d)
427432
return_to_ordinalf_np_vectorized(d)
428433

429434

‎lib/matplotlib/testing/conftest.py‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,8 @@ def pd():
8282
pd=pytest.importorskip('pandas')
8383
try:
8484
frompandas.plottingimport (
85-
register_matplotlib_convertersasregister)
85+
deregister_matplotlib_convertersasderegister)
86+
deregister()
8687
exceptImportError:
87-
frompandas.tseries.converterimportregister
88-
register()
89-
try:
90-
yieldpd
91-
finally:
92-
try:
93-
frompandas.plottingimport (
94-
deregister_matplotlib_convertersasderegister)
95-
exceptImportError:
96-
pass
97-
else:
98-
deregister()
88+
pass
89+
returnpd

‎lib/matplotlib/tests/test_axes.py‎

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

52595259

5260+
deftest_pandas_data_unpack(pd):
5261+
# smoke test for all these different calling methods.
5262+
dates= [datetime.datetime(2018,7,i)foriinrange(1,5)]
5263+
values=np.cumsum(np.random.rand(len(dates)))
5264+
df=pd.DataFrame({"dates":dates,"values":values})
5265+
plt.plot(df["dates"].values,df["values"])
5266+
plt.scatter(df["dates"],df["values"])
5267+
plt.plot("dates","values",data=df)
5268+
plt.scatter(x="dates",y="values",data=df)
5269+
plt.draw()
5270+
5271+
52605272
deftest_axis_set_tick_params_labelsize_labelcolor():
52615273
# Tests fix for issue 4346
52625274
axis_1=plt.subplot()

‎lib/matplotlib/tests/test_dates.py‎

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

586586
deftest_dateboxplot_pandas(pd):
587587
# smoke test that this doesn't fail.
588-
data=np.random.rand(5,2)
588+
data=np.random.rand(5,2)
589589
years=pd.date_range('1/1/2000',
590590
periods=2,freq=pd.DateOffset(years=1)).year
591591
# Does not work

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp