text_extensions_for_pandas/jupyter/widget/table.py
def DataTypeHandler(
    column, value, categories=None, min=None, max=None, description=None
):
    """Returns an interactive widget based on the type of objects in the column"""
    if pd.api.types.is_object_dtype(
        column
    ):  # < ! DANGEROUS. Will treat multi-typed columns as strings. Requires user to be responsible with column types.
        return ipw.Text(value=str(value))
    elif pd.api.types.is_integer_dtype(column):
        return ipw.IntText(value=value)
    elif pd.api.types.is_float_dtype(column):
        return ipw.FloatText(value=value)
    elif pd.api.types.is_bool_dtype(column):
        return ipw.Checkbox(value=bool(value))
    elif pd.api.types.is_categorical_dtype(column):
        if value == np.nan or value == None or str(value) == "nan":
            value = "nan"
        return ipw.Dropdown(options=["nan", *categories.array], value=value)
    # used for handling spans
    elif str(column.dtype) == "SpanDtype" or str(column.dtype) == "TokenSpanDtype":
        return ipw.BoundedIntText(
            value=value, min=min, max=max, description=description
        )
    else:
        return ipw.Text(value=str(value), disabled=True)
Returns an interactive widget based on the type of objects in the column
Returns an interactive widget based on the type of objects in the column
Returns an interactive widget based on the type of objects in the column
def DataTypeHandler(
    column, value, categories=None, min=None, max=None, description=None
):
    if pd.api.types.is_object_dtype(
        column
    ):  
        return ipw.Text(value=str(value))
    elif pd.api.types.is_integer_dtype(column):
        return ipw.IntText(value=value)
    elif pd.api.types.is_float_dtype(column):
        return ipw.FloatText(value=value)
    elif pd.api.types.is_bool_dtype(column):
        return ipw.Checkbox(value=bool(value))
    elif pd.api.types.is_categorical_dtype(column):
        if value == np.nan or value == None or str(value) == "nan":
            value = "nan"
        return ipw.Dropdown(options=["nan", *categories.array], value=value)
    elif str(column.dtype) == "SpanDtype" or str(column.dtype) == "TokenSpanDtype":
        return ipw.BoundedIntText(
            value=value, min=min, max=max, description=description
        )
    else:
        return ipw.Text(value=str(value), disabled=True)
def DataTypeHandler ( column , value , categories = None , min = None , max = None , description = None ) : if pd . api . types . is_object_dtype ( column ) : return ipw . Text ( value = str ( value ) ) elif pd . api . types . is_integer_dtype ( column ) : return ipw . IntText ( value = value ) elif pd . api . types . is_float_dtype ( column ) : return ipw . FloatText ( value = value ) elif pd . api . types . is_bool_dtype ( column ) : return ipw . Checkbox ( value = bool ( value ) ) elif pd . api . types . is_categorical_dtype ( column ) : if value == np . nan or value == None or str ( value ) == "nan" : value = "nan" return ipw . Dropdown ( options = [ "nan" , * categories . array ] , value = value ) elif str ( column . dtype ) == "SpanDtype" or str ( column . dtype ) == "TokenSpanDtype" : return ipw . BoundedIntText ( value = value , min = min , max = max , description = description ) else : return ipw . Text ( value = str ( value ) , disabled = True )
Returns an interactive widget based on the type of objects in the column
Returns an interactive widget based on the type of objects in the column
"""Returns an interactive widget based on the type of objects in the column""" # < ! DANGEROUS. Will treat multi-typed columns as strings. Requires user to be responsible with column types. # used for handling spans
column
value
categories
min
max
description