code: from datetime import datetime
  
  import numpy as np
  import pytest
  
  from pandas import DataFrame, Index, MultiIndex, RangeIndex, Series
  import pandas.util.testing as tm
  
  
  class TestSeriesAlterAxes:
  
      def test_setindex(self, string_series):
          # wrong type
          msg = (r"Index\(\.\.\.\) must be called with a collection of some"
                 r" kind, None was passed")
          with pytest.raises(TypeError, match=msg):
              string_series.index = None
  
          # wrong length
          msg = ("Length mismatch: Expected axis has 30 elements, new"
                 " values have 29 elements")
          with pytest.raises(ValueError, match=msg):
              string_series.index = np.arange(len(string_series) - 1)
  
          # works
          string_series.index = np.arange(len(string_series))
          assert isinstance(string_series.index, Index)
  
      # Renaming
  
      def test_rename(self, datetime_series):
          ts = datetime_series
          renamer = lambda x: x.strftime('%Y%m%d')
          renamed = ts.rename(renamer)
          assert renamed.index[0] == renamer(ts.index[0])
  
          # dict
          rename_dict = dict(zip(ts.index, renamed.index))
          renamed2 = ts.rename(rename_dict)
          tm.assert_series_equal(renamed, renamed2)
  
          # partial dict
          s = Series(np.arange(4), index=['a', 'b', 'c', 'd'], dtype='int64')
          renamed = s.rename({'b': 'foo', 'd': 'bar'})
          tm.assert_index_equal(renamed.index, Index(['a', 'foo', 'c', 'bar']))
  
          # index with name
          renamer = Series(np.arange(4),
                           index=Index(['a', 'b', 'c', 'd'], name='name'),
                           dtype='int64')
          renamed = renamer.rename({})
          assert renamed.index.name == renamer.index.name
  
      def test_rename_by_series(self):
          s = Series(range(5), name='foo')
          renamer = Series({1: 10, 2: 20})
          result = s.rename(renamer)
          expected = Series(range(5), index=[0, 10, 20, 3, 4], name='foo')
          tm.assert_series_equal(result, expected)
  
      def test_rename_set_name(self):
          s = Series(range(4), index=list('abcd'))
          for name in ['foo', 123, 123., datetime(2001, 11, 11), ('foo',)]:
              result = s.rename(name)
              assert result.name == name
              tm.assert_numpy_array_equal(result.index.values, s.index.values)
              assert s.name is None
  
      def test_rename_set_name_inplace(self):
          s = Series(range(3), index=list('abc'))
          for name in ['foo', 123, 123., datetime(2001, 11, 11), ('foo',)]:
              s.rename(name, inplace=True)
              assert s.name == name
  
              exp = np.array(['a', 'b', 'c'], dtype=np.object_)
              tm.assert_numpy_array_equal(s.index.values, exp)
  
      def test_rename_axis_supported(self):
          # Supporting axis for compatibility, detailed in GH-18589
          s = Series(range(5))
          s.rename({}, axis=0)
          s.rename({}, axis='index')
          with pytest.raises(ValueError, match='No axis named 5'):
              s.rename({}, axis=5)
  
      def test_set_name_attribute(self):
          s = Series([1, 2, 3])
          s2 = Series([1, 2, 3], name='bar')
          for name in [7, 7., 'name', datetime(2001, 1, 1), (1,), "\u05D0"]:
              s.name = name
              assert s.name == name
              s2.name = name
              assert s2.name == name
  
      def test_set_name(self):
          s = Series([1, 2, 3])
          s2 = s._set_name('foo')
          assert s2.name == 'foo'
          assert s.name is None
          assert s is not s2
  
      def test_rename_inplace(self, datetime_series):
          renamer = lambda x: x.strftime('%Y%m%d')
          expected = renamer(datetime_series.index[0])
  
          datetime_series.rename(renamer, inplace=True)
          assert datetime_series.index[0] == expected
  
      def test_set_index_makes_timeseries(self):
          idx = tm.makeDateIndex(10)
  
          s = Series(range(10))
          s.index = idx
          assert s.index.is_all_dates
  
      def test_reset_index(self):
          df = tm.makeDataFrame()[:5]
          ser = df.stack()
          ser.index.names = ['hash', 'category']
  
          ser.name = 'value'
          df = ser.reset_index()
          assert 'value' in df
  
          df = ser.reset_index(name='value2')
          assert 'value2' in df
  
          # check inplace
          s = ser.reset_index(drop=True)
          s2 = ser
          s2.reset_index(drop=True, inplace=True)
          tm.assert_series_equal(s, s2)
  
          # level
          index = MultiIndex(levels=[['bar'], ['one', 'two', 'three'], [0, 1]],
                             codes=[[0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2],
                                    [0, 1, 0, 1, 0, 1]])
          s = Series(np.random.randn(6), index=index)
          rs = s.reset_index(level=1)
          assert len(rs.columns) == 2
  
          rs = s.reset_index(level=[0, 2], drop=True)
          tm.assert_index_equal(rs.index, Index(index.get_level_values(1)))
          assert isinstance(rs, Series)
  
      def test_reset_index_name(self):
          s = Series([1, 2, 3], index=Index(range(3), name='x'))
          assert s.reset_index().index.name is None
          assert s.reset_index(drop=True).index.name is None
  
      def test_reset_index_level(self):
          df = DataFrame([[1, 2, 3], [4, 5, 6]],
                         columns=['A', 'B', 'C'])
  
          for levels in ['A', 'B'], [0, 1]:
              # With MultiIndex
              s = df.set_index(['A', 'B'])['C']
  
              result = s.reset_index(level=levels[0])
              tm.assert_frame_equal(result, df.set_index('B'))
  
              result = s.reset_index(level=levels[:1])
              tm.assert_frame_equal(result, df.set_index('B'))
  
              result = s.reset_index(level=levels)
              tm.assert_frame_equal(result, df)
  
              result = df.set_index(['A', 'B']).reset_index(level=levels,
                                                            drop=True)
              tm.assert_frame_equal(result, df[['C']])
  
              with pytest.raises(KeyError, match='Level E '):
                  s.reset_index(level=['A', 'E'])
  
              # With single-level Index
              s = df.set_index('A')['B']
  
              result = s.reset_index(level=levels[0])
              tm.assert_frame_equal(result, df[['A', 'B']])
  
              result = s.reset_index(level=levels[:1])
              tm.assert_frame_equal(result, df[['A', 'B']])
  
              result = s.reset_index(level=levels[0], drop=True)
              tm.assert_series_equal(result, df['B'])
  
              with pytest.raises(IndexError, match='Too many levels'):
                  s.reset_index(level=[0, 1, 2])
  
          # Check that .reset_index([],drop=True) doesn't fail
          result = Series(range(4)).reset_index([], drop=True)
          expected = Series(range(4))
          tm.assert_series_equal(result, expected)
  
      def test_reset_index_range(self):
          # GH 12071
          s = Series(range(2), name='A', dtype='int64')
          series_result = s.reset_index()
          assert isinstance(series_result.index, RangeIndex)
          series_expected = DataFrame([[0, 0], [1, 1]],
                                      columns=['index', 'A'],
                                      index=RangeIndex(stop=2))
          tm.assert_frame_equal(series_result, series_expected)
  
      def test_reorder_levels(self):
          index = MultiIndex(levels=[['bar'], ['one', 'two', 'three'], [0, 1]],
                             codes=[[0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2],
                                    [0, 1, 0, 1, 0, 1]],
                             names=['L0', 'L1', 'L2'])
          s = Series(np.arange(6), index=index)
  
          # no change, position
          result = s.reorder_levels([0, 1, 2])
          tm.assert_series_equal(s, result)
  
          # no change, labels
          result = s.reorder_levels(['L0', 'L1', 'L2'])
          tm.assert_series_equal(s, result)
  
          # rotate, position
          result = s.reorder_levels([1, 2, 0])
          e_idx = MultiIndex(levels=[['one', 'two', 'three'], [0, 1], ['bar']],
                             codes=[[0, 1, 2, 0, 1, 2], [0, 1, 0, 1, 0, 1],
                                    [0, 0, 0, 0, 0, 0]],
                             names=['L1', 'L2', 'L0'])
          expected = Series(np.arange(6), index=e_idx)
          tm.assert_series_equal(result, expected)
  
      def test_rename_axis_mapper(self):
          # GH 19978
          mi = MultiIndex.from_product([['a', 'b', 'c'], [1, 2]],
                                       names=['ll', 'nn'])
          s = Series([i for i in range(len(mi))], index=mi)
  
          result = s.rename_axis(index={'ll': 'foo'})
          assert result.index.names == ['foo', 'nn']
  
          result = s.rename_axis(index=str.upper, axis=0)
          assert result.index.names == ['LL', 'NN']
  
          result = s.rename_axis(index=['foo', 'goo'])
          assert result.index.names == ['foo', 'goo']
  
          with pytest.raises(TypeError, match='unexpected'):
              s.rename_axis(columns='wrong')
  
      def test_rename_axis_inplace(self, datetime_series):
          # GH 15704
          expected = datetime_series.rename_axis('foo')
          result = datetime_series
          no_return = result.rename_axis('foo', inplace=True)
  
          assert no_return is None
          tm.assert_series_equal(result, expected)
  
      @pytest.mark.parametrize('kwargs', [{'mapper': None}, {'index': None}, {}])
      def test_rename_axis_none(self, kwargs):
          # GH 25034
          index = Index(list('abc'), name='foo')
          df = Series([1, 2, 3], index=index)
  
          result = df.rename_axis(**kwargs)
          expected_index = index.rename(None) if kwargs else index
          expected = Series([1, 2, 3], index=expected_index)
          tm.assert_series_equal(result, expected)
  
      def test_set_axis_inplace_axes(self, axis_series):
          # GH14636
          ser = Series(np.arange(4), index=[1, 3, 5, 7], dtype='int64')
  
          expected = ser.copy()
          expected.index = list('abcd')
  
          # inplace=True
          # The FutureWarning comes from the fact that we would like to have
          # inplace default to False some day
          for inplace, warn in [(None, FutureWarning), (True, None)]:
              result = ser.copy()
              kwargs = {'inplace': inplace}
              with tm.assert_produces_warning(warn):
                  result.set_axis(list('abcd'), axis=axis_series, **kwargs)
              tm.assert_series_equal(result, expected)
  
      def test_set_axis_inplace(self):
          # GH14636
  
          s = Series(np.arange(4), index=[1, 3, 5, 7], dtype='int64')
  
          expected = s.copy()
          expected.index = list('abcd')
  
          # inplace=False
          result = s.set_axis(list('abcd'), axis=0, inplace=False)
          tm.assert_series_equal(expected, result)
  
          # omitting the "axis" parameter
          with tm.assert_produces_warning(None):
              result = s.set_axis(list('abcd'), inplace=False)
          tm.assert_series_equal(result, expected)
  
          # wrong values for the "axis" parameter
          for axis in [2, 'foo']:
              with pytest.raises(ValueError, match='No axis named'):
                  s.set_axis(list('abcd'), axis=axis, inplace=False)
  
      def test_set_axis_prior_to_deprecation_signature(self):
          s = Series(np.arange(4), index=[1, 3, 5, 7], dtype='int64')
  
          expected = s.copy()
          expected.index = list('abcd')
  
          for axis in [0, 'index']:
              with tm.assert_produces_warning(FutureWarning):
                  result = s.set_axis(0, list('abcd'), inplace=False)
              tm.assert_series_equal(result, expected)
  
      def test_reset_index_drop_errors(self):
          #  GH 20925
  
          # KeyError raised for series index when passed level name is missing
          s = Series(range(4))
          with pytest.raises(KeyError, match='must be same as name'):
              s.reset_index('wrong', drop=True)
          with pytest.raises(KeyError, match='must be same as name'):
              s.reset_index('wrong')
  
          # KeyError raised for series when level to be dropped is missing
          s = Series(range(4), index=MultiIndex.from_product([[1, 2]] * 2))
          with pytest.raises(KeyError, match='not found'):
              s.reset_index('wrong', drop=True)
  
      def test_droplevel(self):
          # GH20342
          ser = Series([1, 2, 3, 4])
          ser.index = MultiIndex.from_arrays([(1, 2, 3, 4), (5, 6, 7, 8)],
                                             names=['a', 'b'])
          expected = ser.reset_index('b', drop=True)
          result = ser.droplevel('b', axis='index')
          tm.assert_series_equal(result, expected)
          # test that droplevel raises ValueError on axis != 0
          with pytest.raises(ValueError):
              ser.droplevel(1, axis='columns')
   #!/usr/bin/env python
  # coding: utf-8
  
  import os
  import warnings
  
  import numpy as np
  from numpy import random
  
  from pandas.util._decorators import cache_readonly
  import pandas.util._test_decorators as td
  
  from pandas.core.dtypes.api import is_list_like
  
  from pandas import DataFrame, Series
  import pandas.util.testing as tm
  from pandas.util.testing import (
      assert_is_valid_plot_return_object, ensure_clean)
  
  
  """
  This is a common base class used for various plotting tests
  """
  
  
  @td.skip_if_no_mpl
  class TestPlotBase:
  
      def setup_method(self, method):
  
          import matplotlib as mpl
          from pandas.plotting._matplotlib import compat
          mpl.rcdefaults()
  
          self.mpl_ge_2_2_3 = compat._mpl_ge_2_2_3()
          self.mpl_ge_3_0_0 = compat._mpl_ge_3_0_0()
          self.mpl_ge_3_1_0 = compat._mpl_ge_3_1_0()
  
          self.bp_n_objects = 7
          self.polycollection_factor = 2
          self.default_figsize = (6.4, 4.8)
          self.default_tick_position = 'left'
  
          n = 100
          with tm.RNGContext(42):
              gender = np.random.choice(['Male', 'Female'], size=n)
              classroom = np.random.choice(['A', 'B', 'C'], size=n)
  
              self.hist_df = DataFrame({'gender': gender,
                                        'classroom': classroom,
                                        'height': random.normal(66, 4, size=n),
                                        'weight': random.normal(161, 32, size=n),
                                        'category': random.randint(4, size=n)})
  
          self.tdf = tm.makeTimeDataFrame()
          self.hexbin_df = DataFrame({"A": np.random.uniform(size=20),
                                      "B": np.random.uniform(size=20),
                                      "C": np.arange(20) + np.random.uniform(
                                          size=20)})
  
      def teardown_method(self, method):
          tm.close()
  
      @cache_readonly
      def plt(self):
          import matplotlib.pyplot as plt
          return plt
  
      @cache_readonly
      def colorconverter(self):
          import matplotlib.colors as colors
          return colors.colorConverter
  
      def _check_legend_labels(self, axes, labels=None, visible=True):
          """
          Check each axes has expected legend labels
  
          Parameters
          ----------
          axes : matplotlib Axes object, or its list-like
          labels : list-like
              expected legend labels
          visible : bool
              expected legend visibility. labels are checked only when visible is
              True
          """
  
          if visible and (labels is None):
              raise ValueError('labels must be specified when visible is True')
          axes = self._flatten_visible(axes)
          for ax in axes:
              if visible:
                  assert ax.get_legend() is not None
                  self._check_text_labels(ax.get_legend().get_texts(), labels)
              else:
                  assert ax.get_legend() is None
  
      def _check_data(self, xp, rs):
          """
          Check each axes has identical lines
  
          Parameters
          ----------
          xp : matplotlib Axes object
          rs : matplotlib Axes object
          """
          xp_lines = xp.get_lines()
          rs_lines = rs.get_lines()
  
          def check_line(xpl, rsl):
              xpdata = xpl.get_xydata()
              rsdata = rsl.get_xydata()
              tm.assert_almost_equal(xpdata, rsdata)
  
          assert len(xp_lines) == len(rs_lines)
          [check_line(xpl, rsl) for xpl, rsl in zip(xp_lines, rs_lines)]
          tm.close()
  
      def _check_visible(self, collections, visible=True):
          """
          Check each artist is visible or not
  
          Parameters
          ----------
          collections : matplotlib Artist or its list-like
              target Artist or its list or collection
          visible : bool
              expected visibility
          """
          from matplotlib.collections import Collection
          if not isinstance(collections,
                            Collection) and not is_list_like(collections):
              collections = [collections]
  
          for patch in collections:
              assert patch.get_visible() == visible
  
      def _get_colors_mapped(self, series, colors):
          unique = series.unique()
          # unique and colors length can be differed
          # depending on slice value
          mapped = dict(zip(unique, colors))
          return [mapped[v] for v in series.values]
  
      def _check_colors(self, collections, linecolors=None, facecolors=None,
                        mapping=None):
          """
          Check each artist has expected line colors and face colors
  
          Parameters
          ----------
          collections : list-like
              list or collection of target artist
          linecolors : list-like which has the same length as collections
              list of expected line colors
          facecolors : list-like which has the same length as collections
              list of expected face colors
          mapping : Series
              Series used for color grouping key
              used for andrew_curves, parallel_coordinates, radviz test
          """
  
          from matplotlib.lines import Line2D
          from matplotlib.collections import (
              Collection, PolyCollection, LineCollection
          )
          conv = self.colorconverter
          if linecolors is not None:
  
              if mapping is not None:
                  linecolors = self._get_colors_mapped(mapping, linecolors)
                  linecolors = linecolors[:len(collections)]
  
              assert len(collections) == len(linecolors)
              for patch, color in zip(collections, linecolors):
                  if isinstance(patch, Line2D):
                      result = patch.get_color()
                      # Line2D may contains string color expression
                      result = conv.to_rgba(result)
                  elif isinstance(patch, (PolyCollection, LineCollection)):
                      result = tuple(patch.get_edgecolor()[0])
                  else:
                      result = patch.get_edgecolor()
  
                  expected = conv.to_rgba(color)
                  assert result == expected
  
          if facecolors is not None:
  
              if mapping is not None:
                  facecolors = self._get_colors_mapped(mapping, facecolors)
                  facecolors = facecolors[:len(collections)]
  
              assert len(collections) == len(facecolors)
              for patch, color in zip(collections, facecolors):
                  if isinstance(patch, Collection):
                      # returned as list of np.array
                      result = patch.get_facecolor()[0]
                  else:
                      result = patch.get_facecolor()
  
                  if isinstance(result, np.ndarray):
                      result = tuple(result)
  
                  expected = conv.to_rgba(color)
                  assert result == expected
  
      def _check_text_labels(self, texts, expected):
          """
          Check each text has expected labels
  
          Parameters
          ----------
          texts : matplotlib Text object, or its list-like
              target text, or its list
          expected : str or list-like which has the same length as texts
              expected text label, or its list
          """
          if not is_list_like(texts):
              assert texts.get_text() == expected
          else:
              labels = [t.get_text() for t in texts]
              assert len(labels) == len(expected)
              for label, e in zip(labels, expected):
                  assert label == e
  
      def _check_ticks_props(self, axes, xlabelsize=None, xrot=None,
                             ylabelsize=None, yrot=None):
          """
          Check each axes has expected tick properties
  
          Parameters
          ----------
          axes : matplotlib Axes object, or its list-like
          xlabelsize : number
              expected xticks font size
          xrot : number
              expected xticks rotation
          ylabelsize : number
              expected yticks font size
          yrot : number
              expected yticks rotation
          """
          from matplotlib.ticker import NullFormatter
          axes = self._flatten_visible(axes)
          for ax in axes:
              if xlabelsize or xrot:
                  if isinstance(ax.xaxis.get_minor_formatter(), NullFormatter):
                      # If minor ticks has NullFormatter, rot / fontsize are not
                      # retained
                      labels = ax.get_xticklabels()
                  else:
                      labels = ax.get_xticklabels() + ax.get_xticklabels(
                          minor=True)
  
                  for label in labels:
                      if xlabelsize is not None:
                          tm.assert_almost_equal(label.get_fontsize(),
                                                 xlabelsize)
                      if xrot is not None:
                          tm.assert_almost_equal(label.get_rotation(), xrot)
  
              if ylabelsize or yrot:
                  if isinstance(ax.yaxis.get_minor_formatter(), NullFormatter):
                      labels = ax.get_yticklabels()
                  else:
                      labels = ax.get_yticklabels() + ax.get_yticklabels(
                          minor=True)
  
                  for label in labels:
                      if ylabelsize is not None:
                          tm.assert_almost_equal(label.get_fontsize(),
                                                 ylabelsize)
                      if yrot is not None:
                          tm.assert_almost_equal(label.get_rotation(), yrot)
  
      def _check_ax_scales(self, axes, xaxis='linear', yaxis='linear'):
          """
          Check each axes has expected scales
  
          Parameters
          ----------
          axes : matplotlib Axes object, or its list-like
          xaxis : {'linear', 'log'}
              expected xaxis scale
          yaxis :  {'linear', 'log'}
              expected yaxis scale
          """
          axes = self._flatten_visible(axes)
          for ax in axes:
              assert ax.xaxis.get_scale() == xaxis
              assert ax.yaxis.get_scale() == yaxis
  
      def _check_axes_shape(self, axes, axes_num=None, layout=None,
                            figsize=None):
          """
          Check expected number of axes is drawn in expected layout
  
          Parameters
          ----------
          axes : matplotlib Axes object, or its list-like
          axes_num : number
              expected number of axes. Unnecessary axes should be set to
              invisible.
          layout :  tuple
              expected layout, (expected number of rows , columns)
          figsize : tuple
              expected figsize. default is matplotlib default
          """
          from pandas.plotting._matplotlib.tools import _flatten
  
          if figsize is None:
              figsize = self.default_figsize
          visible_axes = self._flatten_visible(axes)
  
          if axes_num is not None:
              assert len(visible_axes) == axes_num
              for ax in visible_axes:
                  # check something drawn on visible axes
                  assert len(ax.get_children()) > 0
  
          if layout is not None:
              result = self._get_axes_layout(_flatten(axes))
              assert result == layout
  
          tm.assert_numpy_array_equal(
              visible_axes[0].figure.get_size_inches(),
              np.array(figsize, dtype=np.float64))
  
      def _get_axes_layout(self, axes):
          x_set = set()
          y_set = set()
          for ax in axes:
              # check axes coordinates to estimate layout
              points = ax.get_position().get_points()
              x_set.add(points[0][0])
              y_set.add(points[0][1])
          return (len(y_set), len(x_set))
  
      def _flatten_visible(self, axes):
          """
          Flatten axes, and filter only visible
  
          Parameters
          ----------
          axes : matplotlib Axes object, or its list-like
  
          """
          from pandas.plotting._matplotlib.tools import _flatten
  
          axes = _flatten(axes)
          axes = [ax for ax in axes if ax.get_visible()]
          return axes
  
      def _check_has_errorbars(self, axes, xerr=0, yerr=0):
          """
          Check axes has expected number of errorbars
  
          Parameters
          ----------
          axes : matplotlib Axes object, or its list-like
          xerr : number
              expected number of x errorbar
          yerr : number
              expected number of y errorbar
          """
          axes = self._flatten_visible(axes)
          for ax in axes:
              containers = ax.containers
              xerr_count = 0
              yerr_count = 0
              for c in containers:
                  has_xerr = getattr(c, 'has_xerr', False)
                  has_yerr = getattr(c, 'has_yerr', False)
                  if has_xerr:
                      xerr_count += 1
                  if has_yerr:
                      yerr_count += 1
              assert xerr == xerr_count
              assert yerr == yerr_count
  
      def _check_box_return_type(self, returned, return_type, expected_keys=None,
                                 check_ax_title=True):
          """
          Check box returned type is correct
  
          Parameters
          ----------
          returned : object to be tested, returned from boxplot
          return_type : str
              return_type passed to boxplot
          expected_keys : list-like, optional
              group labels in subplot case. If not passed,
              the function checks assuming boxplot uses single ax
          check_ax_title : bool
              Whether to check the ax.title is the same as expected_key
              Intended to be checked by calling from ``boxplot``.
              Normal ``plot`` doesn't attach ``ax.title``, it must be disabled.
          """
          from matplotlib.axes import Axes
          types = {'dict': dict, 'axes': Axes, 'both': tuple}
          if expected_keys is None:
              # should be fixed when the returning default is changed
              if return_type is None:
                  return_type = 'dict'
  
              assert isinstance(returned, types[return_type])
              if return_type == 'both':
                  assert isinstance(returned.ax, Axes)
                  assert isinstance(returned.lines, dict)
          else:
              # should be fixed when the returning default is changed
              if return_type is None:
                  for r in self._flatten_visible(returned):
                      assert isinstance(r, Axes)
                  return
  
              assert isinstance(returned, Series)
  
              assert sorted(returned.keys()) == sorted(expected_keys)
              for key, value in returned.items():
                  assert isinstance(value, types[return_type])
                  # check returned dict has correct mapping
                  if return_type == 'axes':
                      if check_ax_title:
                          assert value.get_title() == key
                  elif return_type == 'both':
                      if check_ax_title:
                          assert value.ax.get_title() == key
                      assert isinstance(value.ax, Axes)
                      assert isinstance(value.lines, dict)
                  elif return_type == 'dict':
                      line = value['medians'][0]
                      axes = line.axes
                      if check_ax_title:
                          assert axes.get_title() == key
                  else:
                      raise AssertionError
  
      def _check_grid_settings(self, obj, kinds, kws={}):
          # Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792
  
          import matplotlib as mpl
  
          def is_grid_on():
              xticks = self.plt.gca().xaxis.get_major_ticks()
              yticks = self.plt.gca().yaxis.get_major_ticks()
              # for mpl 2.2.2, gridOn and gridline.get_visible disagree.
              # for new MPL, they are the same.
  
              if self.mpl_ge_3_1_0:
                  xoff = all(not g.gridline.get_visible() for g in xticks)
                  yoff = all(not g.gridline.get_visible() for g in yticks)
              else:
                  xoff = all(not g.gridOn for g in xticks)
                  yoff = all(not g.gridOn for g in yticks)
  
              return not (xoff and yoff)
  
          spndx = 1
          for kind in kinds:
  
              self.plt.subplot(1, 4 * len(kinds), spndx)
              spndx += 1
              mpl.rc('axes', grid=False)
              obj.plot(kind=kind, **kws)
              assert not is_grid_on()
  
              self.plt.subplot(1, 4 * len(kinds), spndx)
              spndx += 1
              mpl.rc('axes', grid=True)
              obj.plot(kind=kind, grid=False, **kws)
              assert not is_grid_on()
  
              if kind != 'pie':
                  self.plt.subplot(1, 4 * len(kinds), spndx)
                  spndx += 1
                  mpl.rc('axes', grid=True)
                  obj.plot(kind=kind, **kws)
                  assert is_grid_on()
  
                  self.plt.subplot(1, 4 * len(kinds), spndx)
                  spndx += 1
                  mpl.rc('axes', grid=False)
                  obj.plot(kind=kind, grid=True, **kws)
                  assert is_grid_on()
  
      def _unpack_cycler(self, rcParams, field='color'):
          """
          Auxiliary function for correctly unpacking cycler after MPL >= 1.5
          """
          return [v[field] for v in rcParams['axes.prop_cycle']]
  
  
  def _check_plot_works(f, filterwarnings='always', **kwargs):
      import matplotlib.pyplot as plt
      ret = None
      with warnings.catch_warnings():
          warnings.simplefilter(filterwarnings)
          try:
              try:
                  fig = kwargs['figure']
              except KeyError:
                  fig = plt.gcf()
  
              plt.clf()
  
              ax = kwargs.get('ax', fig.add_subplot(211))  # noqa
              ret = f(**kwargs)
  
              assert_is_valid_plot_return_object(ret)
  
              try:
                  kwargs['ax'] = fig.add_subplot(212)
                  ret = f(**kwargs)
              except Exception:
                  pass
              else:
                  assert_is_valid_plot_return_object(ret)
  
              with ensure_clean(return_filelike=True) as path:
                  plt.savefig(path)
          finally:
              tm.close(fig)
  
          return ret
  
  
  def curpath():
      pth, _ = os.path.split(os.path.abspath(__file__))
      return pth
  
apis: pandas.Series pandas.util.testing.makeDataFrame pandas.util.testing.assert_numpy_array_equal pandas.MultiIndex.from_arrays pandas.MultiIndex.from_product pandas.Index pandas.DataFrame numpy.random.randn numpy.arange pandas.util.testing.assert_produces_warning pandas.util.testing.assert_series_equal pandas.RangeIndex pandas.MultiIndex pandas.util.testing.assert_frame_equal numpy.array pandas.util.testing.makeDateIndex
apis: pandas.util.testing.close pandas.util.testing.assert_almost_equal pandas.util.testing.assert_is_valid_plot_return_object pandas.util.testing.makeTimeDataFrame matplotlib.pyplot.savefig matplotlib.pyplot.gcf numpy.random.choice matplotlib.rc pandas.plotting._matplotlib.compat._mpl_ge_2_2_3 numpy.random.uniform pandas.plotting._matplotlib.compat._mpl_ge_3_1_0 numpy.random.normal matplotlib.pyplot.clf numpy.arange pandas.core.dtypes.api.is_list_like pandas.plotting._matplotlib.tools._flatten matplotlib.rcdefaults pandas.util.testing.ensure_clean pandas.util.testing.RNGContext pandas.plotting._matplotlib.compat._mpl_ge_3_0_0 numpy.array numpy.random.randint