enum#

class pdcleaner.detection.values.enum(obj, detector=None, values=None, forbidden=False)[source]#

Bases: _SeriesDetector

Detect class values not in a given list.

Intended to be used by the detect method with the keyword ‘enum’.

>>> series.cleaner.detect.enum(...)
>>> series.cleaner.detect('enum',...)

This detection method flags values as potential errors wherever the corresponding Series element is not in the given values list.

Alternatively, if forbidden=True, potential errors are detected when the corresponding Series element is in the given values list.

Note

NA values are not treated as errors.

Parameters:
  • values (list of strings) – Authorized values

  • forbidden (bool (Default: False)) – If forbidden=True, errors are when elements are in the given list

Raises:

ValueError – when values is empty

Examples

>>> series = pd.Series(['cat','cat','dog','bird'])
>>> detector = series.cleaner.detect.enum(values=['cat','dog'])
>>> print(detector.is_error())
0    False
1    False
2    False
3     True
dtype: bool

The detector can also be used with numerical values:

>>> series = pd.Series([5, 5.0, 10, 3])
>>> detector = series.cleaner.detect.enum(values=[5,3])
>>> print(detector.detected())
2    10.0
dtype: float64

Missing values are not treated as errors.

>>> series = pd.Series(['cat',np.nan,'dog','bird'])
>>> detector = series.cleaner.detect.enum(values=['cat','dog'])
>>> print(detector.is_error())
0    False
1    False
2    False
3     True
dtype: bool

Use forbidden=True to detect values in the list as errors

>>> series = pd.Series(['cat','cat','dog','bird'])
>>> detector = \
    series.cleaner.detect.enum(values=['cat','dog'], forbidden=True)
>>> print(detector.is_error())
0     True
1     True
2     True
3    False
dtype: bool

Attributes Summary

forbidden

Is given value a forbidden one (or an expected) ?

index

Indices of the rows detected as errors

n_errors

Number of rows detected as errors

name

obj

The object (Series or DataFrame) containing the data to which the detection is applied

values

List of valid values

Methods Summary

detected()

Series or DataFrame containing only the detected errors

has_errors()

Returns True if any error has been detected, False otherwise

is_error()

Return a boolean same-sized object indicating if the values are flagged as errors

not_error()

Return a boolean same-sized object indicating if the values are NOT flagged as errors

report()

prints a detection report

valid()

Series or DataFrame containing only the valid values

Attributes Documentation

forbidden#

Is given value a forbidden one (or an expected) ?

index#

Indices of the rows detected as errors

n_errors#

Number of rows detected as errors

name = 'enum'#
obj#

The object (Series or DataFrame) containing the data to which the detection is applied

values#

List of valid values

Methods Documentation

detected()#

Series or DataFrame containing only the detected errors

has_errors() bool#

Returns True if any error has been detected, False otherwise

is_error() Series#

Return a boolean same-sized object indicating if the values are flagged as errors

not_error() Series#

Return a boolean same-sized object indicating if the values are NOT flagged as errors

report()#

prints a detection report

valid()#

Series or DataFrame containing only the valid values