<reponame>zachcoleman/sports-ball
import re
from functools import singledispatch

import pandas as pd

from .registry import ETL_FUNCS


@singledispatch
def clean_game_id(blob):
    """Cleans non-alphanumeric characters off the game-id"""
    raise NotImplementedError("Pass a dictionary, pd.Series, or pd.DataFrame")


@clean_game_id.register
def _(blob: dict):
    if "game_id" in blob:
        tmp = re.findall(r"\d+", blob["game_id"])
        if tmp:
            blob["game_id"] = "".join(tmp)
    return blob


@clean_game_id.register
def _(blob: pd.Series):
    blob = blob.apply(lambda x: "".join(re.findall(r"\d+", str(x))))
    return blob


@clean_game_id.register
def _(blob: pd.DataFrame):
    blob["game_id"] = clean_game_id(blob["game_id"])
    return blob


# register functions
# NOTE: the functions are registered here so that
# cross-referencing does not have to go through the registry
# and the dispatch must be defined THEN the registration
ETL_FUNCS.register(tags=["row", "game_id"])(clean_game_id)

import re
from functools import singledispatch

import pandas as pd

from .registry import ETL_FUNCS


@singledispatch
def clean_game_id(blob):
    """Cleans non-alphanumeric characters off the game-id"""
    raise NotImplementedError("Pass a dictionary, pd.Series, or pd.DataFrame")


@clean_game_id.register
def _(blob: dict):
    if "game_id" in blob:
        tmp = re.findall(r"\d+", blob["game_id"])
        if tmp:
            blob["game_id"] = "".join(tmp)
    return blob


@clean_game_id.register
def _(blob: pd.Series):
    blob = blob.apply(lambda x: "".join(re.findall(r"\d+", str(x))))
    return blob


@clean_game_id.register
def _(blob: pd.DataFrame):
    blob["game_id"] = clean_game_id(blob["game_id"])
    return blob


# register functions
# NOTE: the functions are registered here so that
# cross-referencing does not have to go through the registry
# and the dispatch must be defined THEN the registration
ETL_FUNCS.register(tags=["row", "game_id"])(clean_game_id)
Cleans non-alphanumeric characters off the game-id # register functions # NOTE: the functions are registered here so that # cross-referencing does not have to go through the registry # and the dispatch must be defined THEN the registration