Skip to content

Commit c8bfe66

Browse files
committed
Remove mpl compat code
1 parent 12b9a79 commit c8bfe66

File tree

12 files changed

+130
-350
lines changed

12 files changed

+130
-350
lines changed

pandas/plotting/_compat.py

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

2020

21-
_mpl_ge_1_2_1 = _mpl_version('1.2.1', operator.ge)
22-
_mpl_le_1_2_1 = _mpl_version('1.2.1', operator.le)
23-
_mpl_ge_1_3_1 = _mpl_version('1.3.1', operator.ge)
24-
_mpl_ge_1_4_0 = _mpl_version('1.4.0', operator.ge)
25-
_mpl_ge_1_4_1 = _mpl_version('1.4.1', operator.ge)
26-
_mpl_ge_1_5_0 = _mpl_version('1.5.0', operator.ge)
27-
_mpl_ge_2_0_0 = _mpl_version('2.0.0', operator.ge)
28-
_mpl_le_2_0_0 = _mpl_version('2.0.0', operator.le)
2921
_mpl_ge_2_0_1 = _mpl_version('2.0.1', operator.ge)
3022
_mpl_ge_2_1_0 = _mpl_version('2.1.0', operator.ge)
3123
_mpl_ge_2_2_0 = _mpl_version('2.2.0', operator.ge)

pandas/plotting/_converter.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
from pandas.tseries.frequencies import FreqGroup
3636
from pandas.core.indexes.period import Period, PeriodIndex
3737

38-
from pandas.plotting._compat import _mpl_le_2_0_0
39-
4038
# constants
4139
HOURS_PER_DAY = 24.
4240
MIN_PER_HOUR = 60.
@@ -371,13 +369,6 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
371369
if self._tz is dates.UTC:
372370
self._tz._utcoffset = self._tz.utcoffset(None)
373371

374-
# For mpl > 2.0 the format strings are controlled via rcparams
375-
# so do not mess with them. For mpl < 2.0 change the second
376-
# break point and add a musec break point
377-
if _mpl_le_2_0_0():
378-
self.scaled[1. / SEC_PER_DAY] = '%H:%M:%S'
379-
self.scaled[1. / MUSEC_PER_DAY] = '%H:%M:%S.%f'
380-
381372

382373
class PandasAutoDateLocator(dates.AutoDateLocator):
383374

pandas/plotting/_core.py

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030

3131
from pandas.io.formats.printing import pprint_thing
3232

33-
from pandas.plotting._compat import (_mpl_ge_1_3_1,
34-
_mpl_ge_1_5_0,
35-
_mpl_ge_2_0_0,
36-
_mpl_ge_3_0_0)
33+
from pandas.plotting._compat import _mpl_ge_3_0_0
3734
from pandas.plotting._style import (plot_params,
3835
_get_standard_colors)
3936
from pandas.plotting._tools import (_subplots, _flatten, table,
@@ -551,14 +548,6 @@ def plt(self):
551548
import matplotlib.pyplot as plt
552549
return plt
553550

554-
@staticmethod
555-
def mpl_ge_1_3_1():
556-
return _mpl_ge_1_3_1()
557-
558-
@staticmethod
559-
def mpl_ge_1_5_0():
560-
return _mpl_ge_1_5_0()
561-
562551
_need_to_set_index = False
563552

564553
def _get_xticks(self, convert_period=False):
@@ -908,8 +897,7 @@ def _make_plot(self):
908897
scatter = ax.scatter(data[x].values, data[y].values, c=c_values,
909898
label=label, cmap=cmap, **self.kwds)
910899
if cb:
911-
if self.mpl_ge_1_3_1():
912-
cbar_label = c if c_is_column else ''
900+
cbar_label = c if c_is_column else ''
913901
self._plot_colorbar(ax, label=cbar_label)
914902

915903
if label is not None:
@@ -1012,10 +1000,9 @@ def _make_plot(self):
10121000
**kwds)
10131001
self._add_legend_handle(newlines[0], label, index=i)
10141002

1015-
if not _mpl_ge_2_0_0():
1016-
lines = _get_all_lines(ax)
1017-
left, right = _get_xlim(lines)
1018-
ax.set_xlim(left, right)
1003+
lines = _get_all_lines(ax)
1004+
left, right = _get_xlim(lines)
1005+
ax.set_xlim(left, right)
10191006

10201007
@classmethod
10211008
def _plot(cls, ax, x, y, style=None, column_num=None,
@@ -1141,8 +1128,7 @@ def _plot(cls, ax, x, y, style=None, column_num=None,
11411128

11421129
# need to remove label, because subplots uses mpl legend as it is
11431130
line_kwds = kwds.copy()
1144-
if cls.mpl_ge_1_5_0():
1145-
line_kwds.pop('label')
1131+
line_kwds.pop('label')
11461132
lines = MPLPlot._plot(ax, x, y_values, style=style, **line_kwds)
11471133

11481134
# get data from the line to get coordinates for fill_between
@@ -1165,17 +1151,10 @@ def _plot(cls, ax, x, y, style=None, column_num=None,
11651151
cls._update_stacker(ax, stacking_id, y)
11661152

11671153
# LinePlot expects list of artists
1168-
res = [rect] if cls.mpl_ge_1_5_0() else lines
1154+
res = [rect]
11691155
return res
11701156

11711157
def _add_legend_handle(self, handle, label, index=None):
1172-
if not self.mpl_ge_1_5_0():
1173-
from matplotlib.patches import Rectangle
1174-
# Because fill_between isn't supported in legend,
1175-
# specifically add Rectangle handle here
1176-
alpha = self.kwds.get('alpha', None)
1177-
handle = Rectangle((0, 0), 1, 1, fc=handle.get_color(),
1178-
alpha=alpha)
11791158
LinePlot._add_legend_handle(self, handle, label, index=index)
11801159

11811160
def _post_plot_logic(self, ax, data):

pandas/plotting/_style.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
import warnings
66
from contextlib import contextmanager
7-
import re
87

98
import numpy as np
109

1110
from pandas.core.dtypes.common import is_list_like
1211
from pandas.compat import lrange, lmap
1312
import pandas.compat as compat
14-
from pandas.plotting._compat import _mpl_ge_2_0_0
1513

1614

1715
def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
@@ -72,18 +70,9 @@ def _maybe_valid_colors(colors):
7270
# check whether each character can be convertible to colors
7371
maybe_color_cycle = _maybe_valid_colors(list(colors))
7472
if maybe_single_color and maybe_color_cycle and len(colors) > 1:
75-
# Special case for single str 'CN' match and convert to hex
76-
# for supporting matplotlib < 2.0.0
77-
if re.match(r'\AC[0-9]\Z', colors) and _mpl_ge_2_0_0():
78-
hex_color = [c['color']
79-
for c in list(plt.rcParams['axes.prop_cycle'])]
80-
colors = [hex_color[int(colors[1])]]
81-
else:
82-
# this may no longer be required
83-
msg = ("'{0}' can be parsed as both single color and "
84-
"color cycle. Specify each color using a list "
85-
"like ['{0}'] or {1}")
86-
raise ValueError(msg.format(colors, list(colors)))
73+
hex_color = [c['color']
74+
for c in list(plt.rcParams['axes.prop_cycle'])]
75+
colors = [hex_color[int(colors[1])]]
8776
elif maybe_single_color:
8877
colors = [colors]
8978
else:

pandas/tests/plotting/common.py

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _ok_for_gaussian_kde(kind):
3939
except ImportError:
4040
return False
4141

42-
return plotting._compat._mpl_ge_1_5_0()
42+
return True
4343

4444

4545
@td.skip_if_no_mpl
@@ -50,31 +50,14 @@ def setup_method(self, method):
5050
import matplotlib as mpl
5151
mpl.rcdefaults()
5252

53-
self.mpl_le_1_2_1 = plotting._compat._mpl_le_1_2_1()
54-
self.mpl_ge_1_3_1 = plotting._compat._mpl_ge_1_3_1()
55-
self.mpl_ge_1_4_0 = plotting._compat._mpl_ge_1_4_0()
56-
self.mpl_ge_1_5_0 = plotting._compat._mpl_ge_1_5_0()
57-
self.mpl_ge_2_0_0 = plotting._compat._mpl_ge_2_0_0()
5853
self.mpl_ge_2_0_1 = plotting._compat._mpl_ge_2_0_1()
5954
self.mpl_ge_2_2_0 = plotting._compat._mpl_ge_2_2_0()
6055
self.mpl_ge_3_0_0 = plotting._compat._mpl_ge_3_0_0()
6156

62-
if self.mpl_ge_1_4_0:
63-
self.bp_n_objects = 7
64-
else:
65-
self.bp_n_objects = 8
66-
if self.mpl_ge_1_5_0:
67-
# 1.5 added PolyCollections to legend handler
68-
# so we have twice as many items.
69-
self.polycollection_factor = 2
70-
else:
71-
self.polycollection_factor = 1
72-
73-
if self.mpl_ge_2_0_0:
74-
self.default_figsize = (6.4, 4.8)
75-
else:
76-
self.default_figsize = (8.0, 6.0)
77-
self.default_tick_position = 'left' if self.mpl_ge_2_0_0 else 'default'
57+
self.bp_n_objects = 7
58+
self.polycollection_factor = 2
59+
self.default_figsize = (6.4, 4.8)
60+
self.default_tick_position = 'left'
7861

7962
n = 100
8063
with tm.RNGContext(42):
@@ -462,7 +445,7 @@ def _check_box_return_type(self, returned, return_type, expected_keys=None,
462445
assert isinstance(value.lines, dict)
463446
elif return_type == 'dict':
464447
line = value['medians'][0]
465-
axes = line.axes if self.mpl_ge_1_5_0 else line.get_axes()
448+
axes = line.axes
466449
if check_ax_title:
467450
assert axes.get_title() == key
468451
else:
@@ -510,20 +493,6 @@ def is_grid_on():
510493
obj.plot(kind=kind, grid=True, **kws)
511494
assert is_grid_on()
512495

513-
def _maybe_unpack_cycler(self, rcParams, field='color'):
514-
"""
515-
Compat layer for MPL 1.5 change to color cycle
516-
517-
Before: plt.rcParams['axes.color_cycle'] -> ['b', 'g', 'r'...]
518-
After : plt.rcParams['axes.prop_cycle'] -> cycler(...)
519-
"""
520-
if self.mpl_ge_1_5_0:
521-
cyl = rcParams['axes.prop_cycle']
522-
colors = [v[field] for v in cyl]
523-
else:
524-
colors = rcParams['axes.color_cycle']
525-
return colors
526-
527496

528497
def _check_plot_works(f, filterwarnings='always', **kwargs):
529498
import matplotlib.pyplot as plt

pandas/tests/plotting/test_boxplot_method.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pytest
44
import itertools
55
import string
6-
from distutils.version import LooseVersion
76

87
from pandas import Series, DataFrame, MultiIndex
98
from pandas.compat import range, lzip
@@ -21,15 +20,6 @@
2120
""" Test cases for .boxplot method """
2221

2322

24-
def _skip_if_mpl_14_or_dev_boxplot():
25-
# GH 8382
26-
# Boxplot failures on 1.4 and 1.4.1
27-
# Don't need try / except since that's done at class level
28-
import matplotlib
29-
if LooseVersion(matplotlib.__version__) >= LooseVersion('1.4'):
30-
pytest.skip("Matplotlib Regression in 1.4 and current dev.")
31-
32-
3323
@td.skip_if_no_mpl
3424
class TestDataFramePlots(TestPlotBase):
3525

@@ -71,12 +61,12 @@ def test_boxplot_legacy2(self):
7161
# passed ax should be used:
7262
fig, ax = self.plt.subplots()
7363
axes = df.boxplot('Col1', by='X', ax=ax)
74-
ax_axes = ax.axes if self.mpl_ge_1_5_0 else ax.get_axes()
64+
ax_axes = ax.axes
7565
assert ax_axes is axes
7666

7767
fig, ax = self.plt.subplots()
7868
axes = df.groupby('Y').boxplot(ax=ax, return_type='axes')
79-
ax_axes = ax.axes if self.mpl_ge_1_5_0 else ax.get_axes()
69+
ax_axes = ax.axes
8070
assert ax_axes is axes['A']
8171

8272
# Multiple columns with an ax argument should use same figure
@@ -155,7 +145,6 @@ def _check_ax_limits(col, ax):
155145

156146
@pytest.mark.slow
157147
def test_boxplot_empty_column(self):
158-
_skip_if_mpl_14_or_dev_boxplot()
159148
df = DataFrame(np.random.randn(20, 4))
160149
df.loc[:, 0] = np.nan
161150
_check_plot_works(df.boxplot, return_type='axes')

0 commit comments

Comments
 (0)