<commit_before>'''Pandas-based wrapper around ``pyhande.blocking``.'''

import numpy
import matplotlib.pyplot as plt
import mpl_toolkits
import mpl_toolkits.axisartist as mpl_aa
import matplotlib.tight_layout as mpl_tl
import pandas as pd
import pyhande.blocking

def reblock(data, axis=0):
    '''Blocking analysis of correlated data.

Parameters
----------
data: pandas.Series or pandas.DataFrame
    Data to be blocked.  See ``axis`` for order.
axis:
    If non-zero, variables in data are in rows with the columns
    corresponding to the observation values.  Blocking is the performed along
    the rows.  Otherwise each column is a variable, the observations are in the
    columns and blocking is performed down the columns.  Only used if data is
    a pandas.DataFrame.

Returns
-------
data_len: pandas.Series
    Number of data points used in each reblocking iteration.  Note some
    reblocking iterations discard a data point if there were an odd number of
    data points in the previous iteration.
block_info: pandas.DataFrame
    Mean, standard error and estimated standard error for each variable at each
    reblock step.
covariance: pandas.DataFrame
    Covariance matrix at each reblock step.

See also
--------
``pyhande.blocking.reblock``: numpy-based implementation.

``pyhande.pd_utils.reblock`` is a simple wrapper around the numpy-based
implementation.  See there for documentation about the reblocking procedure.
'''

    try:
        columns = [data.name]
        axis = 0
    except AttributeError:
        # Have DataFrame rather than Series.
        if axis:
            columns = data.index.values
        else:
            columns = data.columns.values

    block_stats = pyhande.blocking.reblock(data.values, rowvar=axis)
    data_size = data.shape[axis]
    optimal_blocks = pyhande.blocking.find_optimal_block(data_size, block_stats)
<commit_msg>Use a default name if a series is unnamed.<commit_after>'''Pandas-based wrapper around ``pyhande.blocking``.'''

import numpy
import matplotlib.pyplot as plt
import mpl_toolkits
import mpl_toolkits.axisartist as mpl_aa
import matplotlib.tight_layout as mpl_tl
import pandas as pd
import pyhande.blocking

def reblock(data, axis=0):
    '''Blocking analysis of correlated data.

Parameters
----------
data: pandas.Series or pandas.DataFrame
    Data to be blocked.  See ``axis`` for order.
axis:
    If non-zero, variables in data are in rows with the columns
    corresponding to the observation values.  Blocking is the performed along
    the rows.  Otherwise each column is a variable, the observations are in the
    columns and blocking is performed down the columns.  Only used if data is
    a pandas.DataFrame.

Returns
-------
data_len: pandas.Series
    Number of data points used in each reblocking iteration.  Note some
    reblocking iterations discard a data point if there were an odd number of
    data points in the previous iteration.
block_info: pandas.DataFrame
    Mean, standard error and estimated standard error for each variable at each
    reblock step.
covariance: pandas.DataFrame
    Covariance matrix at each reblock step.

See also
--------
``pyhande.blocking.reblock``: numpy-based implementation.

``pyhande.pd_utils.reblock`` is a simple wrapper around the numpy-based
implementation.  See there for documentation about the reblocking procedure.
'''

    try:
        columns = [data.name]
        if data.name is None:
            columns = ['data']
        axis = 0
    except AttributeError:
        # Have DataFrame rather than Series.
        if axis:
            columns = data.index.values
        else:
            columns = data.columns.values

    block_stats = pyhande.blocking.reblock(data.values, rowvar=axis)
    data_size = data.shape[axis]
    optimal_blocks = pyhande.blocking.find_optimal_block(data_size, block_stats)

{'fraction_non_alphanumeric': 0.07424714434060228, 'fraction_numerical': 0.0010384215991692627, 'mean_word_length': 3.234065934065934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5417648', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1046, 'n_words': 420}