dataprep/eda/missing/compute/common.py
def uni_histogram(
    srs: dd.Series,
    cfg: Config,
    dtype: Optional[DTypeDef] = None,
) -> Tuple[da.Array, ...]:
    """Calculate "histogram" for both numerical and categorical."""

    if is_dtype(detect_dtype(srs, dtype), Continuous()):

        counts, edges = da.histogram(srs, cfg.hist.bins, (srs.min(), srs.max()))
        centers = (edges[:-1] + edges[1:]) / 2

        return counts, centers, edges

    elif is_dtype(detect_dtype(srs, dtype), Nominal()) or is_dtype(
        detect_dtype(srs, dtype), GeoGraphy()
    ):
        # Dask array's unique is way slower than the values_counts on Series
        # See https://github.com/dask/dask/issues/2851
        # centers, counts = da.unique(arr, return_counts=True)

        value_counts = srs.value_counts()

        counts = value_counts.to_dask_array()
        centers = value_counts.index.to_dask_array()

        return (counts, centers)
    else:
        raise ValueError(f"Unsupported dtype {srs.dtype}")
Calculate "histogram" for both numerical and categorical.
Calculate "histogram" for both numerical and categorical.
Calculate " histogram " for both numerical and categorical .
def uni_histogram(
    srs: dd.Series,
    cfg: Config,
    dtype: Optional[DTypeDef] = None,
) -> Tuple[da.Array, ...]:
    if is_dtype(detect_dtype(srs, dtype), Continuous()):
        counts, edges = da.histogram(srs, cfg.hist.bins, (srs.min(), srs.max()))
        centers = (edges[:-1] + edges[1:]) / 2
        return counts, centers, edges
    elif is_dtype(detect_dtype(srs, dtype), Nominal()) or is_dtype(
        detect_dtype(srs, dtype), GeoGraphy()
    ):
        value_counts = srs.value_counts()
        counts = value_counts.to_dask_array()
        centers = value_counts.index.to_dask_array()
        return (counts, centers)
    else:
        raise ValueError(f"Unsupported dtype {srs.dtype}")
def uni_histogram ( srs : dd . Series , cfg : Config , dtype : Optional [ DTypeDef ] = None , ) -> Tuple [ da . Array , ... ] : if is_dtype ( detect_dtype ( srs , dtype ) , Continuous ( ) ) : counts , edges = da . histogram ( srs , cfg . hist . bins , ( srs . min ( ) , srs . max ( ) ) ) centers = ( edges [ : - 1 ] + edges [ 1 : ] ) / 2 return counts , centers , edges elif is_dtype ( detect_dtype ( srs , dtype ) , Nominal ( ) ) or is_dtype ( detect_dtype ( srs , dtype ) , GeoGraphy ( ) ) : value_counts = srs . value_counts ( ) counts = value_counts . to_dask_array ( ) centers = value_counts . index . to_dask_array ( ) return ( counts , centers ) else : raise ValueError ( f"Unsupported dtype {srs.dtype}" )
Calculate "histogram" for both numerical and categorical.
Calculate " histogram " for both numerical and categorical .
"""Calculate "histogram" for both numerical and categorical.""" # Dask array's unique is way slower than the values_counts on Series # See https://github.com/dask/dask/issues/2851 # centers, counts = da.unique(arr, return_counts=True)
srs
dd.Series
cfg
Config
dtype
Optional[DTypeDef]