<commit_before>"""
Adapted from scikits.timeseries by <NAME> & <NAME>
"""

#!!! TODO: Use the fact that axis can have units to simplify the process
import datetime as pydt
from datetime import datetime

from matplotlib import pylab
from matplotlib.ticker import Formatter, Locator
from matplotlib.transforms import nonsingular

import numpy as np

from pandas.tseries.offsets import DateOffset
import pandas.tseries.frequencies as frequencies
from pandas.tseries.frequencies import FreqGroup

from pandas.tseries.period import Period, PeriodIndex
from pandas.tseries.index import DatetimeIndex
from pandas.core.index import Index
from pandas.core.series import Series
import pandas.core.common as com

import warnings

#----------------------------------------------------------------------
# Generic documentation

_doc_parameters = dict(
figsize="""figsize : {None, tuple}
        Size of the figure, as a tuple (width, height) in inches.
        If None, defaults to rc figure.figsize.""",
dpi="""dpi : {None, int}, optional
        Resolution in dots per inches.
        If None, defaults to rc figure.dpi.""",
facecolor="""facecolor : {None, string}, optional
        Background color.
        If None, defaults to rc figure.facecolor.""",
edgecolor="""edgecolor : {None, string}, optional
        Border color.
        If None, defaults to rc figure.edgecolor.""",
linewidth="""linewidth : {float, None}
        Width of the patch edge line.""",
frameon="""frameon : {True, False}
        Whether to draw the frame around the figure.""",
subplotpars="""subplotpars : {None, var}
        A :class:`SubplotParams` instance, defaults to rc""",
mandatoryplotargs="""args : var
        Mandatory arguments for the creation of the subplot.
        These arguments should be given as ``nb_of_rows``, ``nb_of_columns``,
        ``plot_number``, or as a single 3-digit number if the 3 previous numbers
        are all lower than 10.""" )


#----------------------------------------------------------------------
# Plotting functions and monkey patches

def tsplot(series, plotf, *args, **kwargs):
    """
    Plots a Series on the given Matplotlib axes object

    Parameters
    ----------
    axes : Axes
    series : Series

    Notes
    _____
    Supports same args and kwargs as Axes.plot

    """
    # Used inferred freq is possible, need a test case for inferred
    freq = getattr(series.index, 'freq', None)
    if freq is None and hasattr(series.index, 'inferred_freq'):
        freq = series.index.inferred_freq

    if isinstance(freq, DateOffset):
        freq = freq.rule_code
    else:
        freq = frequencies.get_base_alias(freq)

    freq = frequencies.to_calendar_freq(freq)
    # Convert DatetimeIndex to PeriodIndex
    if isinstance(series.index, DatetimeIndex):
        idx = series.index.to_period(freq=freq)
        series = Series(series.values, idx, name=series.name)

    if not isinstance(series.index, PeriodIndex):
        #try to get it to DatetimeIndex then to period
        if series.index.inferred_type == 'datetime':
            idx = DatetimeIndex(series.index).to_period(freq=freq)
            series = Series(series.values, idx, name=series.name)
        else:
            raise TypeError('series argument to tsplot must have '
                            'DatetimeIndex or PeriodIndex')

    if freq != series.index.freq:
        series = series.asfreq(freq)

    series = series.dropna()

    style = kwargs.pop('style', None)

    if 'ax' in kwargs:
        ax = kwargs.pop('ax')
    else:
        ax = plt.gca()

    # Specialized ts plotting attributes for Axes
    ax.freq = freq
    xaxis = ax.get_xaxis()
    xaxis.freq = freq
    xaxis.converter = DateConverter
    ax.legendlabels = [kwargs.get('label', None)]
    ax.view_interval = None
    ax.date_axis_info = None

    # format args and lot
    args = _check_plot_params(series, series.index, freq, style, *args)
    plotted = plotf(ax, *args,  **kwargs)

    format_dateaxis(ax, ax.freq)

    # when adding a right axis (using add_yaxis), for some reason the
    # x axis limits don't get properly set. This gets around the problem
    xlim = ax.get_xlim()
    if xlim[0] == 0.0 and xlim[1] == 1.0:
        # if xlim still at default values, autoscale the axis
        ax.autoscale_view()

    left = series.index[0] #get_datevalue(series.index[0], freq)
    right = series.index[-1] #get_datevalue(series.index[-1], freq)
    ax.set_xlim(left, right)
<commit_msg>BUG: masked arrays to stop interpolating gaps<commit_after>"""
Adapted from scikits.timeseries by <NAME> Gerard-Marchant & <NAME>
"""

#!!! TODO: Use the fact that axis can have units to simplify the process
import datetime as pydt
from datetime import datetime

from matplotlib import pylab
from matplotlib.ticker import Formatter, Locator
from matplotlib.transforms import nonsingular

import numpy as np

from pandas import isnull
from pandas.tseries.offsets import DateOffset
import pandas.tseries.frequencies as frequencies
from pandas.tseries.frequencies import FreqGroup

from pandas.tseries.period import Period, PeriodIndex
from pandas.tseries.index import DatetimeIndex
from pandas.core.index import Index
from pandas.core.series import Series
import pandas.core.common as com

import warnings

#----------------------------------------------------------------------
# Generic documentation

_doc_parameters = dict(
figsize="""figsize : {None, tuple}
        Size of the figure, as a tuple (width, height) in inches.
        If None, defaults to rc figure.figsize.""",
dpi="""dpi : {None, int}, optional
        Resolution in dots per inches.
        If None, defaults to rc figure.dpi.""",
facecolor="""facecolor : {None, string}, optional
        Background color.
        If None, defaults to rc figure.facecolor.""",
edgecolor="""edgecolor : {None, string}, optional
        Border color.
        If None, defaults to rc figure.edgecolor.""",
linewidth="""linewidth : {float, None}
        Width of the patch edge line.""",
frameon="""frameon : {True, False}
        Whether to draw the frame around the figure.""",
subplotpars="""subplotpars : {None, var}
        A :class:`SubplotParams` instance, defaults to rc""",
mandatoryplotargs="""args : var
        Mandatory arguments for the creation of the subplot.
        These arguments should be given as ``nb_of_rows``, ``nb_of_columns``,
        ``plot_number``, or as a single 3-digit number if the 3 previous numbers
        are all lower than 10.""" )


#----------------------------------------------------------------------
# Plotting functions and monkey patches

def tsplot(series, plotf, *args, **kwargs):
    """
    Plots a Series on the given Matplotlib axes object

    Parameters
    ----------
    axes : Axes
    series : Series

    Notes
    _____
    Supports same args and kwargs as Axes.plot

    """
    # Used inferred freq is possible, need a test case for inferred
    freq = getattr(series.index, 'freq', None)
    if freq is None and hasattr(series.index, 'inferred_freq'):
        freq = series.index.inferred_freq

    if isinstance(freq, DateOffset):
        freq = freq.rule_code
    else:
        freq = frequencies.get_base_alias(freq)

    freq = frequencies.to_calendar_freq(freq)
    # Convert DatetimeIndex to PeriodIndex
    if isinstance(series.index, DatetimeIndex):
        idx = series.index.to_period(freq=freq)
        series = Series(series.values, idx, name=series.name)

    if not isinstance(series.index, PeriodIndex):
        #try to get it to DatetimeIndex then to period
        if series.index.inferred_type == 'datetime':
            idx = DatetimeIndex(series.index).to_period(freq=freq)
            series = Series(series.values, idx, name=series.name)
        else:
            raise TypeError('series argument to tsplot must have '
                            'DatetimeIndex or PeriodIndex')

    if freq != series.index.freq:
        series = series.asfreq(freq)

    mask = isnull(series)

    style = kwargs.pop('style', None)

    if 'ax' in kwargs:
        ax = kwargs.pop('ax')
    else:
        ax = plt.gca()

    # Specialized ts plotting attributes for Axes
    ax.freq = freq
    xaxis = ax.get_xaxis()
    xaxis.freq = freq
    xaxis.converter = DateConverter
    ax.legendlabels = [kwargs.get('label', None)]
    ax.view_interval = None
    ax.date_axis_info = None

    # format args and lot
    masked_array = np.ma.array(series.values)
    masked_array = np.ma.masked_where(mask, masked_array)
    args = _check_plot_params(masked_array, series.index, freq, style, *args)
    plotted = plotf(ax, *args,  **kwargs)

    format_dateaxis(ax, ax.freq)

    # when adding a right axis (using add_yaxis), for some reason the
    # x axis limits don't get properly set. This gets around the problem
    xlim = ax.get_xlim()
    if xlim[0] == 0.0 and xlim[1] == 1.0:
        # if xlim still at default values, autoscale the axis
        ax.autoscale_view()

    left = series.index[0] #get_datevalue(series.index[0], freq)
    right = series.index[-1] #get_datevalue(series.index[-1], freq)
    ax.set_xlim(left, right)

{'fraction_non_alphanumeric': 0.12904286810656726, 'fraction_numerical': 0.0030698388334612432, 'mean_word_length': 2.7232653061224488, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2197711', 'n_tokens_mistral': 2719, 'n_tokens_neox': 2613, 'n_words': 868}