23
23
import pandas .util .testing as tm
24
24
import pandas .util ._test_decorators as td
25
25
26
- from pandas .plotting ._compat import _mpl_ge_3_0_0
27
26
from pandas .tests .plotting .common import (TestPlotBase ,
28
27
_skip_if_no_scipy_gaussian_kde )
29
28
@@ -409,23 +408,22 @@ def test_finder_daily(self):
409
408
day_lst = [10 , 40 , 252 , 400 , 950 , 2750 , 10000 ]
410
409
411
410
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 )
414
413
else :
415
414
xpl1 = [7565 , 7564 , 7553 , 7546 , 7518 , 7428 , 7066 ]
416
415
xpl2 = [7566 , 7564 , 7554 , 7546 , 7519 , 7429 , 7066 ]
417
416
418
417
rs1 = []
419
418
rs2 = []
420
419
for i , n in enumerate (day_lst ):
421
- xp = xpl1 [i ]
422
420
rng = bdate_range ('1999-1-1' , periods = n )
423
421
ser = Series (np .random .randn (len (rng )), rng )
424
422
_ , ax = self .plt .subplots ()
425
423
ser .plot (ax = ax )
426
424
xaxis = ax .get_xaxis ()
427
425
rs1 .append (xaxis .get_majorticklocs ()[0 ])
428
- xp = xpl2 [ i ]
426
+
429
427
vmin , vmax = ax .get_xlim ()
430
428
ax .set_xlim (vmin + 0.9 , vmax )
431
429
rs2 .append (xaxis .get_majorticklocs ()[0 ])
@@ -434,36 +432,30 @@ def test_finder_daily(self):
434
432
if rs1 != xpl1 or rs2 != xpl2 :
435
433
print (matplotlib .__version__ , np .__version__ ,
436
434
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
441
437
442
438
@pytest .mark .slow
443
439
def test_finder_quarterly (self ):
444
440
yrs = [3.5 , 11 ]
445
441
446
442
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 :
450
446
xpl1 = [68 , 68 ]
451
447
xpl2 = [72 , 68 ]
452
- else :
453
- xpl1 = [72 , 68 ]
454
- xpl2 = xpl1
455
448
456
449
rs1 = []
457
450
rs2 = []
458
451
for i , n in enumerate (yrs ):
459
- xp = xpl1 [i ]
460
452
rng = period_range ('1987Q2' , periods = int (n * 4 ), freq = 'Q' )
461
453
ser = Series (np .random .randn (len (rng )), rng )
462
454
_ , ax = self .plt .subplots ()
463
455
ser .plot (ax = ax )
464
456
xaxis = ax .get_xaxis ()
465
457
rs1 .append (xaxis .get_majorticklocs ()[0 ])
466
- xp = xpl2 [ i ]
458
+
467
459
(vmin , vmax ) = ax .get_xlim ()
468
460
ax .set_xlim (vmin + 0.9 , vmax )
469
461
rs2 .append (xaxis .get_majorticklocs ()[0 ])
@@ -472,36 +464,30 @@ def test_finder_quarterly(self):
472
464
if rs1 != xpl1 or rs2 != xpl2 :
473
465
print (matplotlib .__version__ , np .__version__ ,
474
466
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
479
469
480
470
@pytest .mark .slow
481
471
def test_finder_monthly (self ):
482
472
yrs = [1.15 , 2.5 , 4 , 11 ]
483
473
484
474
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 )
490
477
else :
491
- xpl1 = [216 , 216 , 216 , 204 ]
478
+ xpl1 = [216 , 216 , 204 , 204 ]
492
479
xpl2 = [216 , 216 , 216 , 204 ]
493
480
494
481
rs1 = []
495
482
rs2 = []
496
483
for i , n in enumerate (yrs ):
497
- xp = xpl1 [i ]
498
484
rng = period_range ('1987Q2' , periods = int (n * 12 ), freq = 'M' )
499
485
ser = Series (np .random .randn (len (rng )), rng )
500
486
_ , ax = self .plt .subplots ()
501
487
ser .plot (ax = ax )
502
488
xaxis = ax .get_xaxis ()
503
489
rs1 .append (xaxis .get_majorticklocs ()[0 ])
504
- xp = xpl2 [ i ]
490
+
505
491
vmin , vmax = ax .get_xlim ()
506
492
ax .set_xlim (vmin + 0.9 , vmax )
507
493
rs2 .append (xaxis .get_majorticklocs ()[0 ])
@@ -510,10 +496,8 @@ def test_finder_monthly(self):
510
496
if rs1 != xpl1 or rs2 != xpl2 :
511
497
print (matplotlib .__version__ , np .__version__ ,
512
498
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
517
501
518
502
def test_finder_monthly_long (self ):
519
503
rng = period_range ('1988Q1' , periods = 24 * 12 , freq = 'M' )
@@ -528,11 +512,10 @@ def test_finder_monthly_long(self):
528
512
@pytest .mark .slow
529
513
def test_finder_annual (self ):
530
514
if self .mpl_ge_3_0_0 or not self .mpl_ge_2_0_1 :
515
+ # 2.0.0 or >= 3.0.0
531
516
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 ]
534
517
else :
535
- xp = [1987 , 1987 , 1990 , 1990 , 1995 , 2020 , 1970 , 1970 ]
518
+ xp = [1986 , 1986 , 1990 , 1990 , 1995 , 2020 , 1970 , 1970 ]
536
519
537
520
xp = [Period (x , freq = 'A' ).ordinal for x in xp ]
538
521
rs = []
@@ -547,8 +530,7 @@ def test_finder_annual(self):
547
530
548
531
if rs != xp :
549
532
print (matplotlib .__version__ , np .__version__ , rs , xp )
550
- for res , exp in zip (rs , xp ):
551
- assert res == exp
533
+ assert rs == xp
552
534
553
535
@pytest .mark .slow
554
536
def test_finder_minutely (self ):
@@ -559,7 +541,7 @@ def test_finder_minutely(self):
559
541
ser .plot (ax = ax )
560
542
xaxis = ax .get_xaxis ()
561
543
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
563
545
if rs != xp :
564
546
print (matplotlib .__version__ , np .__version__ , rs , xp )
565
547
assert rs == xp
@@ -590,7 +572,7 @@ def test_gaps(self):
590
572
assert len (lines ) == 1
591
573
l = lines [0 ]
592
574
data = l .get_xydata ()
593
- if _mpl_ge_3_0_0 :
575
+ if self . mpl_ge_3_0_0 :
594
576
data = np .ma .MaskedArray (data , mask = isna (data ), fill_value = np .nan )
595
577
if not isinstance (data , np .ma .core .MaskedArray ):
596
578
print (matplotlib .__version__ , np .__version__ , type (data ))
@@ -609,7 +591,7 @@ def test_gaps(self):
609
591
assert len (lines ) == 1
610
592
l = lines [0 ]
611
593
data = l .get_xydata ()
612
- if _mpl_ge_3_0_0 :
594
+ if self . mpl_ge_3_0_0 :
613
595
data = np .ma .MaskedArray (data , mask = isna (data ), fill_value = np .nan )
614
596
if not isinstance (data , np .ma .core .MaskedArray ):
615
597
print (matplotlib .__version__ , np .__version__ , type (data ))
@@ -628,7 +610,7 @@ def test_gaps(self):
628
610
assert len (lines ) == 1
629
611
l = lines [0 ]
630
612
data = l .get_xydata ()
631
- if _mpl_ge_3_0_0 :
613
+ if self . mpl_ge_3_0_0 :
632
614
data = np .ma .MaskedArray (data , mask = isna (data ), fill_value = np .nan )
633
615
if not isinstance (data , np .ma .core .MaskedArray ):
634
616
print (matplotlib .__version__ , np .__version__ , type (data ))
@@ -652,7 +634,7 @@ def test_gap_upsample(self):
652
634
assert len (ax .right_ax .get_lines ()) == 1
653
635
l = lines [0 ]
654
636
data = l .get_xydata ()
655
- if _mpl_ge_3_0_0 :
637
+ if self . mpl_ge_3_0_0 :
656
638
data = np .ma .MaskedArray (data , mask = isna (data ), fill_value = np .nan )
657
639
658
640
if not isinstance (data , np .ma .core .MaskedArray ):
0 commit comments