Skip to content

Commit ec93bdb

Browse files
committed
Clean up diff/switches in test_datetimelike
1 parent 31dc4fa commit ec93bdb

File tree

1 file changed

+25
-43
lines changed

1 file changed

+25
-43
lines changed

pandas/tests/plotting/test_datetimelike.py

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import pandas.util.testing as tm
2424
import pandas.util._test_decorators as td
2525

26-
from pandas.plotting._compat import _mpl_ge_3_0_0
2726
from pandas.tests.plotting.common import (TestPlotBase,
2827
_skip_if_no_scipy_gaussian_kde)
2928

@@ -409,23 +408,22 @@ def test_finder_daily(self):
409408
day_lst = [10, 40, 252, 400, 950, 2750, 10000]
410409

411410
if self.mpl_ge_3_0_0 or not self.mpl_ge_2_0_1:
412-
xpl1 = [7566] * len(day_lst)
413-
xpl2 = xpl1
411+
# 2.0.0 and >= 3.0.0
412+
xpl1 = xpl2 = [Period('1999-1-1', freq='B').ordinal] * len(day_lst)
414413
else:
415414
xpl1 = [7565, 7564, 7553, 7546, 7518, 7428, 7066]
416415
xpl2 = [7566, 7564, 7554, 7546, 7519, 7429, 7066]
417416

418417
rs1 = []
419418
rs2 = []
420419
for i, n in enumerate(day_lst):
421-
xp = xpl1[i]
422420
rng = bdate_range('1999-1-1', periods=n)
423421
ser = Series(np.random.randn(len(rng)), rng)
424422
_, ax = self.plt.subplots()
425423
ser.plot(ax=ax)
426424
xaxis = ax.get_xaxis()
427425
rs1.append(xaxis.get_majorticklocs()[0])
428-
xp = xpl2[i]
426+
429427
vmin, vmax = ax.get_xlim()
430428
ax.set_xlim(vmin + 0.9, vmax)
431429
rs2.append(xaxis.get_majorticklocs()[0])
@@ -434,36 +432,30 @@ def test_finder_daily(self):
434432
if rs1 != xpl1 or rs2 != xpl2:
435433
print(matplotlib.__version__, np.__version__,
436434
rs1, xpl1, rs2, xpl2)
437-
for rs, xp in zip(rs1, xpl1):
438-
assert rs == xp
439-
for rs, xp in zip(rs2, xpl2):
440-
assert rs == xp
435+
assert rs1 == xpl1
436+
assert rs2 == xpl2
441437

442438
@pytest.mark.slow
443439
def test_finder_quarterly(self):
444440
yrs = [3.5, 11]
445441

446442
if self.mpl_ge_3_0_0 or not self.mpl_ge_2_0_1:
447-
xpl1 = [72, 72]
448-
xpl2 = [72, 72]
449-
elif self.mpl_ge_2_0_1:
443+
# 2.0.0 and >= 3.0.0
444+
xpl1 = xpl2 = [Period('1988Q1').ordinal] * len(yrs)
445+
else:
450446
xpl1 = [68, 68]
451447
xpl2 = [72, 68]
452-
else:
453-
xpl1 = [72, 68]
454-
xpl2 = xpl1
455448

456449
rs1 = []
457450
rs2 = []
458451
for i, n in enumerate(yrs):
459-
xp = xpl1[i]
460452
rng = period_range('1987Q2', periods=int(n * 4), freq='Q')
461453
ser = Series(np.random.randn(len(rng)), rng)
462454
_, ax = self.plt.subplots()
463455
ser.plot(ax=ax)
464456
xaxis = ax.get_xaxis()
465457
rs1.append(xaxis.get_majorticklocs()[0])
466-
xp = xpl2[i]
458+
467459
(vmin, vmax) = ax.get_xlim()
468460
ax.set_xlim(vmin + 0.9, vmax)
469461
rs2.append(xaxis.get_majorticklocs()[0])
@@ -472,36 +464,30 @@ def test_finder_quarterly(self):
472464
if rs1 != xpl1 or rs2 != xpl2:
473465
print(matplotlib.__version__, np.__version__,
474466
rs1, xpl1, rs2, xpl2)
475-
for rs, xp in zip(rs1, xpl1):
476-
assert rs == xp
477-
for rs, xp in zip(rs2, xpl2):
478-
assert rs == xp
467+
assert rs1 == xpl1
468+
assert rs2 == xpl2
479469

480470
@pytest.mark.slow
481471
def test_finder_monthly(self):
482472
yrs = [1.15, 2.5, 4, 11]
483473

484474
if self.mpl_ge_3_0_0 or not self.mpl_ge_2_0_1:
485-
xpl1 = [216] * 4
486-
xpl2 = xpl1
487-
elif self.mpl_ge_2_0_1:
488-
xpl1 = [216, 216, 204, 204]
489-
xpl2 = [216, 216, 216, 204]
475+
# 2.0.0 or >= 3.0.0
476+
xpl1 = xpl2 = [Period('Jan 1988').ordinal] * len(yrs)
490477
else:
491-
xpl1 = [216, 216, 216, 204]
478+
xpl1 = [216, 216, 204, 204]
492479
xpl2 = [216, 216, 216, 204]
493480

494481
rs1 = []
495482
rs2 = []
496483
for i, n in enumerate(yrs):
497-
xp = xpl1[i]
498484
rng = period_range('1987Q2', periods=int(n * 12), freq='M')
499485
ser = Series(np.random.randn(len(rng)), rng)
500486
_, ax = self.plt.subplots()
501487
ser.plot(ax=ax)
502488
xaxis = ax.get_xaxis()
503489
rs1.append(xaxis.get_majorticklocs()[0])
504-
xp = xpl2[i]
490+
505491
vmin, vmax = ax.get_xlim()
506492
ax.set_xlim(vmin + 0.9, vmax)
507493
rs2.append(xaxis.get_majorticklocs()[0])
@@ -510,10 +496,8 @@ def test_finder_monthly(self):
510496
if rs1 != xpl1 or rs2 != xpl2:
511497
print(matplotlib.__version__, np.__version__,
512498
rs1, xpl1, rs2, xpl2)
513-
for rs, xp in zip(rs1, xpl1):
514-
assert rs == xp
515-
for rs, xp in zip(rs2, xpl2):
516-
assert rs == xp
499+
assert rs1 == xpl1
500+
assert rs2 == xpl2
517501

518502
def test_finder_monthly_long(self):
519503
rng = period_range('1988Q1', periods=24 * 12, freq='M')
@@ -528,11 +512,10 @@ def test_finder_monthly_long(self):
528512
@pytest.mark.slow
529513
def test_finder_annual(self):
530514
if self.mpl_ge_3_0_0 or not self.mpl_ge_2_0_1:
515+
# 2.0.0 or >= 3.0.0
531516
xp = [1987, 1988, 1990, 1990, 1995, 2020, 2070, 2170]
532-
elif self.mpl_ge_2_0_1:
533-
xp = [1986, 1986, 1990, 1990, 1995, 2020, 1970, 1970]
534517
else:
535-
xp = [1987, 1987, 1990, 1990, 1995, 2020, 1970, 1970]
518+
xp = [1986, 1986, 1990, 1990, 1995, 2020, 1970, 1970]
536519

537520
xp = [Period(x, freq='A').ordinal for x in xp]
538521
rs = []
@@ -547,8 +530,7 @@ def test_finder_annual(self):
547530

548531
if rs != xp:
549532
print(matplotlib.__version__, np.__version__, rs, xp)
550-
for res, exp in zip(rs, xp):
551-
assert res == exp
533+
assert rs == xp
552534

553535
@pytest.mark.slow
554536
def test_finder_minutely(self):
@@ -559,7 +541,7 @@ def test_finder_minutely(self):
559541
ser.plot(ax=ax)
560542
xaxis = ax.get_xaxis()
561543
rs = xaxis.get_majorticklocs()[0]
562-
xp = Period('1999-01-01 00:00', freq='Min').ordinal
544+
xp = Period('1/1/1999', freq='Min').ordinal
563545
if rs != xp:
564546
print(matplotlib.__version__, np.__version__, rs, xp)
565547
assert rs == xp
@@ -590,7 +572,7 @@ def test_gaps(self):
590572
assert len(lines) == 1
591573
l = lines[0]
592574
data = l.get_xydata()
593-
if _mpl_ge_3_0_0:
575+
if self.mpl_ge_3_0_0:
594576
data = np.ma.MaskedArray(data, mask=isna(data), fill_value=np.nan)
595577
if not isinstance(data, np.ma.core.MaskedArray):
596578
print(matplotlib.__version__, np.__version__, type(data))
@@ -609,7 +591,7 @@ def test_gaps(self):
609591
assert len(lines) == 1
610592
l = lines[0]
611593
data = l.get_xydata()
612-
if _mpl_ge_3_0_0:
594+
if self.mpl_ge_3_0_0:
613595
data = np.ma.MaskedArray(data, mask=isna(data), fill_value=np.nan)
614596
if not isinstance(data, np.ma.core.MaskedArray):
615597
print(matplotlib.__version__, np.__version__, type(data))
@@ -628,7 +610,7 @@ def test_gaps(self):
628610
assert len(lines) == 1
629611
l = lines[0]
630612
data = l.get_xydata()
631-
if _mpl_ge_3_0_0:
613+
if self.mpl_ge_3_0_0:
632614
data = np.ma.MaskedArray(data, mask=isna(data), fill_value=np.nan)
633615
if not isinstance(data, np.ma.core.MaskedArray):
634616
print(matplotlib.__version__, np.__version__, type(data))
@@ -652,7 +634,7 @@ def test_gap_upsample(self):
652634
assert len(ax.right_ax.get_lines()) == 1
653635
l = lines[0]
654636
data = l.get_xydata()
655-
if _mpl_ge_3_0_0:
637+
if self.mpl_ge_3_0_0:
656638
data = np.ma.MaskedArray(data, mask=isna(data), fill_value=np.nan)
657639

658640
if not isinstance(data, np.ma.core.MaskedArray):

0 commit comments

Comments
 (0)