<commit_before>import numbers

import numpy as np
import pandas as pd
import pandas.api.types as pdtypes

from ..exceptions import PlotnineError

__all__ = ['after_stat', 'after_scale', 'stage']

_TPL_EVAL_FAIL = """\
Could not evaluate the '{}' mapping: '{}' \
(original error: {})"""

_TPL_BAD_EVAL_TYPE = """\
The '{}' mapping: '{}' produced a value of type '{}',\
but only single items and lists/arrays can be used. \
(original error: {})"""


class stage:
    """
    Stage allows you evaluating mapping at more than one stage

    You can evaluate an expression of a variable in a dataframe, and
    later evaluate an expression that modifies the values mapped to
    the scale.

    Parameters
    ----------
    start : expression | array_like | scalar
        Aesthetic expression using primary variables from the layer
        data.
    after_stat : expression
        Aesthetic expression using variables calculated by the stat.
    after_scale : expression
        Aesthetic expression using aesthetics of the layer.
    """
    def __init__(self, start=None, after_stat=None, after_scale=None):
        self.start = start
        self.after_stat = after_stat
        self.after_scale = after_scale

    def __repr__(self):
        return (
            f'stage(start={repr(self.start)}, '
            f'after_stat={repr(self.after_stat)}, '
            f'after_scale={repr(self.after_scale)})'
        )


def after_stat(x):
    """
    Evaluate mapping after statistic has been calculated

    Parameters
    ----------
    x : str
        An expression

    See Also
    --------
    :func:`after_scale` : For how to alter aesthetics after the data has been
        mapped by the scale.
    :class:`stage` : For how to map to aesthetics at more than one stage of
        the plot building pipeline.
    """
    return stage(after_stat=x)<commit_msg>DOC: Use shorter repr for aes stages if possible<commit_after>import numbers

import numpy as np
import pandas as pd
import pandas.api.types as pdtypes

from ..exceptions import PlotnineError

__all__ = ['after_stat', 'after_scale', 'stage']

_TPL_EVAL_FAIL = """\
Could not evaluate the '{}' mapping: '{}' \
(original error: {})"""

_TPL_BAD_EVAL_TYPE = """\
The '{}' mapping: '{}' produced a value of type '{}',\
but only single items and lists/arrays can be used. \
(original error: {})"""


class stage:
    """
    Stage allows you evaluating mapping at more than one stage

    You can evaluate an expression of a variable in a dataframe, and
    later evaluate an expression that modifies the values mapped to
    the scale.

    Parameters
    ----------
    start : expression | array_like | scalar
        Aesthetic expression using primary variables from the layer
        data.
    after_stat : expression
        Aesthetic expression using variables calculated by the stat.
    after_scale : expression
        Aesthetic expression using aesthetics of the layer.
    """
    def __init__(self, start=None, after_stat=None, after_scale=None):
        self.start = start
        self.after_stat = after_stat
        self.after_scale = after_scale

    def __repr__(self):
        # Shorter representation when the mapping happens at a
        # single stage
        if self.after_stat is None and self.after_scale is None:
            return f'{repr(self.start)}'
        if self.start is None and self.after_scale is None:
            return f'after_stat({repr(self.after_stat)})'
        if self.start is None and self.after_stat is None:
            return f'after_scale({repr(self.after_scale)})'
        return (
            f'stage(start={repr(self.start)}, '
            f'after_stat={repr(self.after_stat)}, '
            f'after_scale={repr(self.after_scale)})'
        )


def after_stat(x):
    """
    Evaluate mapping after statistic has been calculated

    Parameters
    ----------
    x : str
        An expression

    See Also
    --------
    :func:`after_scale` : For how to alter aesthetics after the data has been
        mapped by the scale.
    :class:`stage` : For how to map to aesthetics at more than one stage of
        the plot building pipeline.
    """
    return stage(after_stat=x)
{'fraction_non_alphanumeric': 0.09952267303102626, 'fraction_numerical': 0.0, 'mean_word_length': 2.6067125645438898, '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': '4308004', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1157, 'n_words': 417}