janitor/utils.py
def _data_checks_pivot_longer(
    df,
    index,
    column_names,
    names_to,
    values_to,
    names_sep,
    names_pattern,
    dtypes,
):

    """
    This function raises errors or warnings if the arguments have the wrong
    python type, or if an unneeded argument is provided. It also raises an
    error message if `names_pattern` is a list/tuple of regular expressions,
    and `names_to` is not a list/tuple, and the lengths do not match.
    This function is executed before proceeding to the computation phase.

    Type annotations are not provided because this function is where type
    checking happens.
    """

    if any(
        (
            isinstance(df.index, pd.MultiIndex),
            isinstance(df.columns, pd.MultiIndex),
        ),
    ):
        raise ValueError(
            """
            pivot_longer is designed for single index dataframes;
            for MultiIndex , kindly use pandas.melt.
            """
        )

    if index is not None:
        if isinstance(index, str):
            index = [index]
        check("index", index, [list, tuple, Pattern])

    if column_names is not None:
        if isinstance(column_names, str):
            column_names = [column_names]
        check("column_names", column_names, [list, tuple, Pattern])

    check("names_to", names_to, [list, tuple, str])

    if isinstance(names_to, str):
        names_to = [names_to]

    if isinstance(names_to, (list, tuple)):
        if not all(isinstance(word, str) for word in names_to):
            raise TypeError(
                "All entries in `names_to` argument must be strings."
            )

        if len(names_to) > 1:
            if all((names_pattern, names_sep)):
                raise ValueError(
                    """
                    Only one of names_pattern or names_sep
                    should be provided.
                    """
                )

            if all(
                (names_pattern is None, names_sep is None)
            ):  # write test for this
                raise ValueError(
                    """
                    If `names_to` is a list/tuple, then either
                    `names_sep` or `names_pattern` must be supplied.
                    """
                )

            if ".value" in names_to:
                if names_to.count(".value") > 1:
                    raise ValueError(
                        "Column name `.value` must not be duplicated."
                    )
        if len(names_to) == 1:
            # names_sep creates more than one column
            # whereas regex with names_pattern can be limited to one column
            if names_sep is not None:
                raise ValueError(
                    """
                    For a single names_to value,
                    names_sep is not required.
                    """
                )
    if names_pattern is not None:
        check("names_pattern", names_pattern, [str, Pattern, List, Tuple])
        if isinstance(names_pattern, (list, tuple)):
            if not all(
                isinstance(word, (str, Pattern)) for word in names_pattern
            ):
                raise TypeError(
                    """
                    All entries in ``names_pattern`` argument
                    must be regular expressions.
                    """
                )

            if len(names_pattern) != len(names_to):
                raise ValueError(
                    """
                    Length of ``names_to`` does not match
                    number of patterns.
                    """
                )

            if ".value" in names_to:
                raise ValueError(
                    """
                    ``.value`` not accepted if ``names_pattern``
                    is a list/tuple.
                    """
                )

    if names_sep is not None:
        check("names_sep", names_sep, [str, Pattern])

    if dtypes is not None:
        check("dtypes", dtypes, [dict])

    check("values_to", values_to, [str])

    return (
        df,
        index,
        column_names,
        names_to,
        values_to,
        names_sep,
        names_pattern,
        dtypes,
    )

    This function raises errors or warnings if the arguments have the wrong
    python type, or if an unneeded argument is provided. It also raises an
    error message if `names_pattern` is a list/tuple of regular expressions,
    and `names_to` is not a list/tuple, and the lengths do not match.
    This function is executed before proceeding to the computation phase.

    Type annotations are not provided because this function is where type
    checking happens.
    
This function raises errors or warnings if the arguments have the wrong
python type, or if an unneeded argument is provided. It also raises an
error message if `names_pattern` is a list/tuple of regular expressions,
and `names_to` is not a list/tuple, and the lengths do not match.
This function is executed before proceeding to the computation phase.

Type annotations are not provided because this function is where type
checking happens.
This function raises errors or warnings if the arguments have the wrong python type or if an unneeded argument is provided . It also raises an error message if ` names_pattern ` is a list / tuple of regular expressions and ` names_to ` is not a list / tuple and the lengths do not match . This function is executed before proceeding to the computation phase . Type annotations are not provided because this function is where type checking happens .
def _data_checks_pivot_longer(
    df,
    index,
    column_names,
    names_to,
    values_to,
    names_sep,
    names_pattern,
    dtypes,
):
    if any(
        (
            isinstance(df.index, pd.MultiIndex),
            isinstance(df.columns, pd.MultiIndex),
        ),
    ):
        raise ValueError(
            """
            pivot_longer is designed for single index dataframes;
            for MultiIndex , kindly use pandas.melt.
            """
        )
    if index is not None:
        if isinstance(index, str):
            index = [index]
        check("index", index, [list, tuple, Pattern])
    if column_names is not None:
        if isinstance(column_names, str):
            column_names = [column_names]
        check("column_names", column_names, [list, tuple, Pattern])
    check("names_to", names_to, [list, tuple, str])
    if isinstance(names_to, str):
        names_to = [names_to]
    if isinstance(names_to, (list, tuple)):
        if not all(isinstance(word, str) for word in names_to):
            raise TypeError(
                "All entries in `names_to` argument must be strings."
            )
        if len(names_to) > 1:
            if all((names_pattern, names_sep)):
                raise ValueError(
                    """
                    Only one of names_pattern or names_sep
                    should be provided.
                    """
                )
            if all(
                (names_pattern is None, names_sep is None)
            ):  
                raise ValueError(
                    """
                    If `names_to` is a list/tuple, then either
                    `names_sep` or `names_pattern` must be supplied.
                    """
                )
            if ".value" in names_to:
                if names_to.count(".value") > 1:
                    raise ValueError(
                        "Column name `.value` must not be duplicated."
                    )
        if len(names_to) == 1:
            if names_sep is not None:
                raise ValueError(
                    """
                    For a single names_to value,
                    names_sep is not required.
                    """
                )
    if names_pattern is not None:
        check("names_pattern", names_pattern, [str, Pattern, List, Tuple])
        if isinstance(names_pattern, (list, tuple)):
            if not all(
                isinstance(word, (str, Pattern)) for word in names_pattern
            ):
                raise TypeError(
                    """
                    All entries in ``names_pattern`` argument
                    must be regular expressions.
                    """
                )
            if len(names_pattern) != len(names_to):
                raise ValueError(
                    """
                    Length of ``names_to`` does not match
                    number of patterns.
                    """
                )
            if ".value" in names_to:
                raise ValueError(
                    """
                    ``.value`` not accepted if ``names_pattern``
                    is a list/tuple.
                    """
                )
    if names_sep is not None:
        check("names_sep", names_sep, [str, Pattern])
    if dtypes is not None:
        check("dtypes", dtypes, [dict])
    check("values_to", values_to, [str])
    return (
        df,
        index,
        column_names,
        names_to,
        values_to,
        names_sep,
        names_pattern,
        dtypes,
    )
def _data_checks_pivot_longer ( df , index , column_names , names_to , values_to , names_sep , names_pattern , dtypes , ) : if any ( ( isinstance ( df . index , pd . MultiIndex ) , isinstance ( df . columns , pd . MultiIndex ) , ) , ) : raise ValueError ( """
            pivot_longer is designed for single index dataframes;
            for MultiIndex , kindly use pandas.melt.
            """ ) if index is not None : if isinstance ( index , str ) : index = [ index ] check ( "index" , index , [ list , tuple , Pattern ] ) if column_names is not None : if isinstance ( column_names , str ) : column_names = [ column_names ] check ( "column_names" , column_names , [ list , tuple , Pattern ] ) check ( "names_to" , names_to , [ list , tuple , str ] ) if isinstance ( names_to , str ) : names_to = [ names_to ] if isinstance ( names_to , ( list , tuple ) ) : if not all ( isinstance ( word , str ) for word in names_to ) : raise TypeError ( "All entries in `names_to` argument must be strings." ) if len ( names_to ) > 1 : if all ( ( names_pattern , names_sep ) ) : raise ValueError ( """
                    Only one of names_pattern or names_sep
                    should be provided.
                    """ ) if all ( ( names_pattern is None , names_sep is None ) ) : raise ValueError ( """
                    If `names_to` is a list/tuple, then either
                    `names_sep` or `names_pattern` must be supplied.
                    """ ) if ".value" in names_to : if names_to . count ( ".value" ) > 1 : raise ValueError ( "Column name `.value` must not be duplicated." ) if len ( names_to ) == 1 : if names_sep is not None : raise ValueError ( """
                    For a single names_to value,
                    names_sep is not required.
                    """ ) if names_pattern is not None : check ( "names_pattern" , names_pattern , [ str , Pattern , List , Tuple ] ) if isinstance ( names_pattern , ( list , tuple ) ) : if not all ( isinstance ( word , ( str , Pattern ) ) for word in names_pattern ) : raise TypeError ( """
                    All entries in ``names_pattern`` argument
                    must be regular expressions.
                    """ ) if len ( names_pattern ) != len ( names_to ) : raise ValueError ( """
                    Length of ``names_to`` does not match
                    number of patterns.
                    """ ) if ".value" in names_to : raise ValueError ( """
                    ``.value`` not accepted if ``names_pattern``
                    is a list/tuple.
                    """ ) if names_sep is not None : check ( "names_sep" , names_sep , [ str , Pattern ] ) if dtypes is not None : check ( "dtypes" , dtypes , [ dict ] ) check ( "values_to" , values_to , [ str ] ) return ( df , index , column_names , names_to , values_to , names_sep , names_pattern , dtypes , )
This function raises errors or warnings if the arguments have the wrong
python type, or if an unneeded argument is provided.
This function raises errors or warnings if the arguments have the wrong python type or if an unneeded argument is provided .
"""
    This function raises errors or warnings if the arguments have the wrong
    python type, or if an unneeded argument is provided. It also raises an
    error message if `names_pattern` is a list/tuple of regular expressions,
    and `names_to` is not a list/tuple, and the lengths do not match.
    This function is executed before proceeding to the computation phase.

    Type annotations are not provided because this function is where type
    checking happens.
    """ # write test for this # names_sep creates more than one column # whereas regex with names_pattern can be limited to one column
df
index
column_names
names_to
values_to
names_sep
names_pattern
dtypes