value#

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

Bases: _SeriesDetector

Detect class values different from a value.

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

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

This detection method flags values as potential errors wherever the corresponding Series element is different or not from a given value.

Note

NA values are not treated as errors.

Parameters:
  • value (value) – Authorized value

  • forbidden (bool (Default: False)) – If forbidden=True, errors are elements equal to value

  • check_type (Bool (Default: True)) – Checks the type of the value if True (3.0 is not the same type as 3)

Raises:

ValueError – when value is None

Examples

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

By default, the type of value and data is checked and must be identical

>>> series = pd.Series([5, 5.0])
>>> detector = series.cleaner.detect.value(value=5)
>>> print(detector.is_error())
0    False
1    True
dtype: bool
>>> series = pd.Series([5, 5.0])
>>> detector = series.cleaner.detect.value(value=5, check_type=False)
>>> print(detector.is_error())
0    False
1    False
dtype: bool

Missing values are not treated as errors.

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

Use the forbidden=True argument to detect a given value as an error

>>> series= pd.Series([1, 2, 3])
>>> detector = series.cleaner.detect('value', value=1, forbidden=True)
>>> print(detector.is_error())
0     True
1    False
2    False
dtype: bool

Attributes Summary

check_type

Authorized value

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

value

Authorized value

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

check_type#

Authorized value

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 = 'value'#
obj#

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

value#

Authorized value

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