Skip to content

Commit

Permalink
MNT: Remove unused code paths (#1965)
Browse files Browse the repository at this point in the history
* TST: pandas==1.0 compat

* Remove old matplotlib paths

* Remove old scipy paths

* Remove _set_spine_position

The behavior that this function addressed has been resolved in matplotlib 1.4:
matplotlib/matplotlib#3104

* Clean more old compat code paths

Removed a few try/except clauses aimed to cover old matplotlib/pandas
versions that are no longer supported.

* Remove __future__ imports

* Improve code style

(cherry picked from commit 5498cdb)
  • Loading branch information
MaozGelbart authored and mwaskom committed Feb 27, 2020
1 parent eb3d088 commit 1c3f6f8
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 318 deletions.
1 change: 0 additions & 1 deletion doc/sphinxext/gallery_generator.py
Expand Up @@ -4,7 +4,6 @@
Lightly modified from the mpld3 project.
"""
from __future__ import division
import os
import os.path as op
import re
Expand Down
1 change: 0 additions & 1 deletion seaborn/algorithms.py
@@ -1,5 +1,4 @@
"""Algorithms to support fitting routines in seaborn plotting functions."""
from __future__ import division
import numbers
import numpy as np
import warnings
Expand Down
22 changes: 4 additions & 18 deletions seaborn/axisgrid.py
@@ -1,6 +1,4 @@
from __future__ import division
from itertools import product
from distutils.version import LooseVersion
import warnings
from textwrap import dedent

Expand Down Expand Up @@ -232,9 +230,6 @@ def __init__(self, data, row=None, col=None, hue=None, col_wrap=None,
margin_titles=False, xlim=None, ylim=None, subplot_kws=None,
gridspec_kws=None, size=None):

MPL_GRIDSPEC_VERSION = LooseVersion('1.4')
OLD_MPL = LooseVersion(mpl.__version__) < MPL_GRIDSPEC_VERSION

# Handle deprecations
if size is not None:
height = size
Expand Down Expand Up @@ -315,12 +310,6 @@ def __init__(self, data, row=None, col=None, hue=None, col_wrap=None,
subplot_kw=subplot_kws,
gridspec_kw=gridspec_kws)

if OLD_MPL:
kwargs.pop('gridspec_kw', None)
if gridspec_kws:
msg = "gridspec module only available in mpl >= {}"
warnings.warn(msg.format(MPL_GRIDSPEC_VERSION))

fig, axes = plt.subplots(nrow, ncol, **kwargs)
self.axes = axes

Expand Down Expand Up @@ -446,14 +435,14 @@ def __init__(self, data, row=None, col=None, hue=None, col_wrap=None,
{margin_titles}
{{x, y}}lim: tuples, optional
Limits for each of the axes on each facet (only relevant when
share{{x, y}} is True.
share{{x, y}} is True).
subplot_kws : dict, optional
Dictionary of keyword arguments passed to matplotlib subplot(s)
methods.
gridspec_kws : dict, optional
Dictionary of keyword arguments passed to matplotlib's ``gridspec``
module (via ``plt.subplots``). Requires matplotlib >= 1.4 and is
ignored if ``col_wrap`` is not ``None``.
module (via ``plt.subplots``). Ignored if ``col_wrap`` is not
``None``.
See Also
--------
Expand Down Expand Up @@ -1303,10 +1292,7 @@ def __init__(self, data, hue=None, hue_order=None, palette=None,
if corner:
hide_indices = np.triu_indices_from(axes, 1)
for i, j in zip(*hide_indices):
try:
axes[i, j].remove()
except NotImplementedError: # Problem on old matplotlibs?
axes[i, j].set_axis_off()
axes[i, j].remove()
axes[i, j] = None

self.fig = fig
Expand Down
21 changes: 2 additions & 19 deletions seaborn/categorical.py
@@ -1,4 +1,3 @@
from __future__ import division
from textwrap import dedent
import colorsys
import numpy as np
Expand Down Expand Up @@ -325,15 +324,7 @@ def infer_orient(self, x, y, orient=None):
orient = str(orient)

def is_categorical(s):
try:
# Correct way, but does not exist in older Pandas
try:
return pd.api.types.is_categorical_dtype(s)
except AttributeError:
return pd.core.common.is_categorical_dtype(s)
except AttributeError:
# Also works, but feels hackier
return str(s.dtype) == "categorical"
return pd.api.types.is_categorical_dtype(s)

def is_not_numeric(s):
try:
Expand Down Expand Up @@ -709,15 +700,7 @@ def estimate_densities(self, bw, cut, scale, scale_hue, gridsize):

def fit_kde(self, x, bw):
"""Estimate a KDE for a vector of data with flexible bandwidth."""
# Allow for the use of old scipy where `bw` is fixed
try:
kde = stats.gaussian_kde(x, bw)
except TypeError:
kde = stats.gaussian_kde(x)
if bw != "scott": # scipy default
msg = ("Ignoring bandwidth choice, "
"please upgrade scipy to use a different bandwidth.")
warnings.warn(msg, UserWarning)
kde = stats.gaussian_kde(x, bw)

# Extract the numeric bandwidth from the KDE object
bw_used = kde.factor
Expand Down
7 changes: 1 addition & 6 deletions seaborn/distributions.py
@@ -1,5 +1,4 @@
"""Plotting functions for visualizing distributions."""
from __future__ import division
import numpy as np
from scipy import stats
import pandas as pd
Expand All @@ -8,7 +7,6 @@
import matplotlib.transforms as tx
from matplotlib.collections import LineCollection
import warnings
from distutils.version import LooseVersion

try:
import statsmodels.nonparametric.api as smnp
Expand Down Expand Up @@ -216,10 +214,7 @@ def distplot(a, bins=None, hist=True, kde=True, rug=False, fit=None,
if bins is None:
bins = min(_freedman_diaconis_bins(a), 50)
hist_kws.setdefault("alpha", 0.4)
if LooseVersion(mpl.__version__) < LooseVersion("2.2"):
hist_kws.setdefault("normed", norm_hist)
else:
hist_kws.setdefault("density", norm_hist)
hist_kws.setdefault("density", norm_hist)

orientation = "horizontal" if vertical else "vertical"
hist_color = hist_kws.pop("color", color)
Expand Down
1 change: 0 additions & 1 deletion seaborn/matrix.py
@@ -1,5 +1,4 @@
"""Functions to visualize matrices of data."""
from __future__ import division
import itertools
import warnings

Expand Down
1 change: 0 additions & 1 deletion seaborn/miscplot.py
@@ -1,4 +1,3 @@
from __future__ import division
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
Expand Down
1 change: 0 additions & 1 deletion seaborn/palettes.py
@@ -1,4 +1,3 @@
from __future__ import division
import colorsys
from itertools import cycle

Expand Down
43 changes: 14 additions & 29 deletions seaborn/rcmod.py
@@ -1,15 +1,11 @@
"""Control plot style and scaling using the matplotlib rcParams interface."""
from distutils.version import LooseVersion
import warnings
import functools
import matplotlib as mpl
import warnings
from cycler import cycler
from . import palettes, _orig_rc_params


mpl_ge_150 = LooseVersion(mpl.__version__) >= '1.5.0'
mpl_ge_2 = LooseVersion(mpl.__version__) >= '2.0'


__all__ = ["set", "reset_defaults", "reset_orig",
"axes_style", "set_style", "plotting_context", "set_context",
"set_palette"]
Expand Down Expand Up @@ -37,30 +33,23 @@
"lines.solid_capstyle",

"patch.edgecolor",
"patch.force_edgecolor",

"image.cmap",
"font.family",
"font.sans-serif",

]

if mpl_ge_2:
"xtick.bottom",
"xtick.top",
"ytick.left",
"ytick.right",

_style_keys.extend([
"axes.spines.left",
"axes.spines.bottom",
"axes.spines.right",
"axes.spines.top",

"patch.force_edgecolor",

"xtick.bottom",
"xtick.top",
"ytick.left",
"ytick.right",

"axes.spines.left",
"axes.spines.bottom",
"axes.spines.right",
"axes.spines.top",

])
]

_context_keys = [

Expand Down Expand Up @@ -540,12 +529,8 @@ def set_palette(palette, n_colors=None, desat=None, color_codes=False):
"""
colors = palettes.color_palette(palette, n_colors, desat)
if mpl_ge_150:
from cycler import cycler
cyl = cycler('color', colors)
mpl.rcParams['axes.prop_cycle'] = cyl
else:
mpl.rcParams["axes.color_cycle"] = list(colors)
cyl = cycler('color', colors)
mpl.rcParams['axes.prop_cycle'] = cyl
mpl.rcParams["patch.facecolor"] = colors[0]
if color_codes:
try:
Expand Down
7 changes: 1 addition & 6 deletions seaborn/regression.py
@@ -1,5 +1,4 @@
"""Plotting functions for linear models (broadly construed)."""
from __future__ import division
import copy
from textwrap import dedent
import warnings
Expand Down Expand Up @@ -420,11 +419,7 @@ def lineplot(self, ax, kws):

# Draw the regression line and confidence interval
line, = ax.plot(grid, yhat, **kws)
try:
line.sticky_edges.x[:] = edges # Prevent mpl from adding margin
except AttributeError:
msg = "Cannot set sticky_edges; requires newer matplotlib."
warnings.warn(msg, UserWarning)
line.sticky_edges.x[:] = edges # Prevent mpl from adding margin
if err_bands is not None:
ax.fill_between(grid, *err_bands, facecolor=fill_color, alpha=.15)

Expand Down
7 changes: 1 addition & 6 deletions seaborn/relational.py
@@ -1,7 +1,5 @@
from __future__ import division
from itertools import product
from textwrap import dedent
from distutils.version import LooseVersion
import warnings

import numpy as np
Expand All @@ -23,10 +21,7 @@

class _RelationalPlotter(object):

if LooseVersion(mpl.__version__) >= "2.0":
default_markers = ["o", "X", "s", "P", "D", "^", "v", "p"]
else:
default_markers = ["o", "s", "D", "^", "v", "p"]
default_markers = ["o", "X", "s", "P", "D", "^", "v", "p"]
default_dashes = ["", (4, 1.5), (1, 1),
(3, 1, 1.5, 1), (5, 1, 1, 1),
(5, 1, 2, 1, 2, 1)]
Expand Down
4 changes: 0 additions & 4 deletions seaborn/tests/test_axisgrid.py
Expand Up @@ -14,8 +14,6 @@
except ImportError:
import pandas.util.testing as tm

from distutils.version import LooseVersion

from .. import axisgrid as ag
from .. import rcmod
from ..palettes import color_palette
Expand Down Expand Up @@ -831,8 +829,6 @@ def test_specific_nonsquare_axes_with_array(self):
nt.assert_equal(g.y_vars, list(y_vars))
nt.assert_true(not g.square_grid)

@pytest.mark.xfail(LooseVersion(mpl.__version__) < "1.5",
reason="Expected failure on older matplotlib")
def test_corner(self):

plot_vars = ["x", "y", "z"]
Expand Down

0 comments on commit 1c3f6f8

Please sign in to comment.