code: def _maybe_resample(series, ax, kwargs):
      # resample against axes freq if necessary
      freq, ax_freq = _get_freq(ax, series)
  
      if freq is None:  # pragma: no cover
          raise ValueError(
              "Cannot use dynamic axis without frequency info"
          )
  
      # Convert DatetimeIndex to PeriodIndex
      if isinstance(series.index, ABCDatetimeIndex):
          series = series.to_period(freq=freq)
  
      if ax_freq is not None and freq != ax_freq:
          if is_superperiod(freq, ax_freq):  # upsample input
              series = series.copy()
              series.index = series.index.asfreq(ax_freq, how="s")
              freq = ax_freq
          elif _is_sup(freq, ax_freq):  # one is weekly
              how = kwargs.pop("how", "last")
              series = getattr(series.resample("D"), how)().dropna()
              series = getattr(series.resample(ax_freq), how)().dropna()
              freq = ax_freq
          elif is_subperiod(freq, ax_freq) or _is_sub(freq, ax_freq):
              _upsample_others(ax, freq, kwargs)
          else:  # pragma: no cover
              raise ValueError("Incompatible frequency conversion")
      return freq, series
  
imports: import functools
  from matplotlib import pylab
  import numpy
  from pandas._libs.tslibs.frequencies import FreqGroup, get_base_alias, get_freq, is_subperiod, is_superperiod
  from pandas._libs.tslibs.period import Period
  import pandas.compat
  from pandas.core.dtypes.generic import ABCDatetimeIndex, ABCPeriodIndex, ABCTimedeltaIndex
  from pandas.io.formats.printing import pprint_thing
  from pandas.plotting._converter import TimeSeries_DateFormatter, TimeSeries_DateLocator, TimeSeries_TimedeltaFormatter
  import pandas.tseries.frequencies
  from pandas.tseries.offsets import DateOffset
label_desc: Use image node_id 2 for calling a global function with example usage: _maybe_resample(series, ax, kwargs) and returns: freq,  series