from typing import Optional
from typing import Union
from typing import cast
from typing import Dict


def validate_axis(axis: Optional[Union[int, str]] = 0, none_axis: int = 0) -> int:
    """Check the given axis is valid."""
    # convert to numeric axis
    axis = cast(
        Dict[Optional[Union[int, str]], int], {None: none_axis, "index": 0, "columns": 1}
    ).get(axis, axis)
    if axis in (none_axis, 0, 1):
        return cast(int, axis)
    else:
        raise ValueError("No axis named {0}".format(axis))