Skip to content

Commit 02cb47e

Browse files
committed
clean up mpl-compat
1 parent 9ede144 commit 02cb47e

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

pandas/plotting/_compat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ def inner():
1818
return inner
1919

2020

21+
_mpl_eq_2_0_2 = _mpl_version('2.0.2', operator.eq)
2122
_mpl_ge_2_0_2 = _mpl_version('2.0.2', operator.ge)
2223
_mpl_ge_2_1_0 = _mpl_version('2.1.0', operator.ge)
24+
_mpl_eq_2_2_0 = _mpl_version('2.2.0', operator.eq)
2325
_mpl_ge_2_2_0 = _mpl_version('2.2.0', operator.ge)
2426
_mpl_ge_2_2_2 = _mpl_version('2.2.2', operator.ge)
2527
_mpl_ge_3_0_0 = _mpl_version('3.0.0', operator.ge)

pandas/tests/plotting/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ def setup_method(self, method):
5353
import matplotlib as mpl
5454
mpl.rcdefaults()
5555

56+
self.mpl_eq_2_0_2 = plotting._compat._mpl_eq_2_0_2()
5657
self.mpl_ge_2_0_2 = plotting._compat._mpl_ge_2_0_2()
5758
self.mpl_ge_2_1_0 = plotting._compat._mpl_ge_2_1_0()
59+
self.mpl_eq_2_2_0 = plotting._compat._mpl_eq_2_2_0()
5860
self.mpl_ge_2_2_0 = plotting._compat._mpl_ge_2_2_0()
5961
self.mpl_ge_2_2_2 = plotting._compat._mpl_ge_2_2_2()
6062
self.mpl_ge_3_0_0 = plotting._compat._mpl_ge_3_0_0()

pandas/tests/plotting/test_datetimelike.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,10 @@ def test_get_finder(self):
406406
def test_finder_daily(self):
407407
day_lst = [10, 40, 252, 400, 950, 2750, 10000]
408408

409-
if (self.mpl_ge_3_0_0
410-
or (self.mpl_ge_2_1_0 and not self.mpl_ge_2_2_2)):
411-
# 2.2.0 (exactly) or >= 3.0.0
409+
if self.mpl_ge_3_0_0 or self.mpl_eq_2_0_2 or self.mpl_eq_2_2_0:
410+
# 2.0.2, 2.2.0 (exactly) or >= 3.0.0
412411
xpl1 = xpl2 = [Period('1999-1-1', freq='B').ordinal] * len(day_lst)
413-
else: # 2.0.2, 2.1.0, 2.2.2, 2.2.3, 2.2.4
412+
else: # 2.1.0, 2.2.2, 2.2.3, 2.2.4
414413
xpl1 = [7565, 7564, 7553, 7546, 7518, 7428, 7066]
415414
xpl2 = [7566, 7564, 7554, 7546, 7519, 7429, 7066]
416415

@@ -436,11 +435,10 @@ def test_finder_daily(self):
436435
def test_finder_quarterly(self):
437436
yrs = [3.5, 11]
438437

439-
if (self.mpl_ge_3_0_0
440-
or (self.mpl_ge_2_1_0 and not self.mpl_ge_2_2_2)):
441-
# 2.2.0 (exactly) or >= 3.0.0
438+
if self.mpl_ge_3_0_0 or self.mpl_eq_2_0_2 or self.mpl_eq_2_2_0:
439+
# 2.0.2, 2.2.0 (exactly) or >= 3.0.0
442440
xpl1 = xpl2 = [Period('1988Q1').ordinal] * len(yrs)
443-
else: # 2.0.2, 2.1.0, 2.2.2, 2.2.3, 2.2.4
441+
else: # 2.1.0, 2.2.2, 2.2.3, 2.2.4
444442
xpl1 = [68, 68]
445443
xpl2 = [72, 68]
446444

@@ -466,11 +464,10 @@ def test_finder_quarterly(self):
466464
def test_finder_monthly(self):
467465
yrs = [1.15, 2.5, 4, 11]
468466

469-
if (self.mpl_ge_3_0_0
470-
or (self.mpl_ge_2_1_0 and not self.mpl_ge_2_2_2)):
471-
# 2.2.0 (exactly) or >= 3.0.0
467+
if self.mpl_ge_3_0_0 or self.mpl_eq_2_0_2 or self.mpl_eq_2_2_0:
468+
# 2.0.2, 2.2.0 (exactly) or >= 3.0.0
472469
xpl1 = xpl2 = [Period('Jan 1988').ordinal] * len(yrs)
473-
else: # 2.0.2, 2.1.0, 2.2.2, 2.2.3, 2.2.4
470+
else: # 2.1.0, 2.2.2, 2.2.3, 2.2.4
474471
xpl1 = [216, 216, 204, 204]
475472
xpl2 = [216, 216, 216, 204]
476473

@@ -504,11 +501,10 @@ def test_finder_monthly_long(self):
504501

505502
@pytest.mark.slow
506503
def test_finder_annual(self):
507-
if (self.mpl_ge_3_0_0
508-
or (self.mpl_ge_2_1_0 and not self.mpl_ge_2_2_2)):
509-
# 2.2.0 (exactly) or >= 3.0.0
504+
if self.mpl_ge_3_0_0 or self.mpl_eq_2_0_2 or self.mpl_eq_2_2_0:
505+
# 2.0.2, 2.2.0 (exactly) or >= 3.0.0
510506
xp = [1987, 1988, 1990, 1990, 1995, 2020, 2070, 2170]
511-
else: # 2.0.2, 2.1.0, 2.2.2, 2.2.3, 2.2.4
507+
else: # 2.1.0, 2.2.2, 2.2.3, 2.2.4
512508
xp = [1986, 1986, 1990, 1990, 1995, 2020, 1970, 1970]
513509

514510
xp = [Period(x, freq='A').ordinal for x in xp]
@@ -560,9 +556,8 @@ def test_gaps(self):
560556
line = lines[0]
561557
data = line.get_xydata()
562558

563-
if (self.mpl_ge_3_0_0
564-
or (self.mpl_ge_2_1_0 and not self.mpl_ge_2_2_2)):
565-
# 2.2.0 (exactly) or >= 3.0.0
559+
if self.mpl_ge_3_0_0 or self.mpl_eq_2_0_2 or self.mpl_eq_2_2_0:
560+
# 2.0.2, 2.2.0 (exactly) or >= 3.0.0
566561
data = np.ma.MaskedArray(data, mask=isna(data), fill_value=np.nan)
567562

568563
assert isinstance(data, np.ma.core.MaskedArray)
@@ -581,9 +576,8 @@ def test_gaps(self):
581576
line = lines[0]
582577
data = line.get_xydata()
583578

584-
if (self.mpl_ge_3_0_0
585-
or (self.mpl_ge_2_1_0 and not self.mpl_ge_2_2_2)):
586-
# 2.2.0 (exactly) or >= 3.0.0
579+
if self.mpl_ge_3_0_0 or self.mpl_eq_2_0_2 or self.mpl_eq_2_2_0:
580+
# 2.0.2, 2.2.0 (exactly) or >= 3.0.0
587581
data = np.ma.MaskedArray(data, mask=isna(data), fill_value=np.nan)
588582

589583
assert isinstance(data, np.ma.core.MaskedArray)
@@ -601,9 +595,8 @@ def test_gaps(self):
601595
assert len(lines) == 1
602596
line = lines[0]
603597
data = line.get_xydata()
604-
if (self.mpl_ge_3_0_0
605-
or (self.mpl_ge_2_1_0 and not self.mpl_ge_2_2_2)):
606-
# 2.2.0 (exactly) or >= 3.0.0
598+
if self.mpl_ge_3_0_0 or self.mpl_eq_2_0_2 or self.mpl_eq_2_2_0:
599+
# 2.0.2, 2.2.0 (exactly) or >= 3.0.0
607600
data = np.ma.MaskedArray(data, mask=isna(data), fill_value=np.nan)
608601

609602
assert isinstance(data, np.ma.core.MaskedArray)
@@ -626,9 +619,8 @@ def test_gap_upsample(self):
626619

627620
line = lines[0]
628621
data = line.get_xydata()
629-
if (self.mpl_ge_3_0_0
630-
or (self.mpl_ge_2_1_0 and not self.mpl_ge_2_2_2)):
631-
# 2.2.0 (exactly) or >= 3.0.0
622+
if self.mpl_ge_3_0_0 or self.mpl_eq_2_0_2 or self.mpl_eq_2_2_0:
623+
# 2.0.2, 2.2.0 (exactly) or >= 3.0.0
632624
data = np.ma.MaskedArray(data, mask=isna(data), fill_value=np.nan)
633625

634626
assert isinstance(data, np.ma.core.MaskedArray)

0 commit comments

Comments
 (0)