Skip to content

coerce

coerce ¤

Numeric coercion that reports what it could not convert.

pd.to_numeric(..., errors="coerce") turns every value it cannot parse into NaN without a trace, so a column of "12,5" strings or a stray "n/a" silently drops out of every downstream calculation. :func:to_numeric_checked performs the same coercion and emits a :class:~ts_shape.errors.DataQualityWarning naming how many non-null values were not numeric.

:func:bool_or_false reads a run/state column as plain bool with missing values as False, without relying on pandas' deprecated silent downcasting of object columns (.fillna(False).astype(bool)).

to_numeric_checked ¤

to_numeric_checked(
    values: Series, *, what: str
) -> pd.Series

Coerce values to numbers, warning when non-null values become NaN.

Parameters:

Name Type Description Default
values Series

Values to coerce.

required
what str

Short description of the values for the warning message, e.g. "counter column 'value_integer'".

required

Returns:

Type Description
Series

A numeric Series aligned with values. Values that are not numeric

Series

are NaN.

Warns:

Type Description
DataQualityWarning

When at least one non-null value is not numeric.

bool_or_false ¤

bool_or_false(values: Series) -> pd.Series

values as a NumPy bool Series; missing values are False.

Known values are cast with bool (as .astype(bool) does), so the result equals values.fillna(False).astype(bool) for every dtype, but an object column is never filled first, which pandas 2.2 reports as a deprecated downcast.

Parameters:

Name Type Description Default
values Series

State values (bool, nullable boolean, numbers or object).

required

Returns:

Type Description
Series

A bool Series with the index and name of values.