date_range#
- class pdcleaner.detection.datetimes.date_range(obj, detector=None, lower=Timestamp('1677-09-21 00:12:43.145224193'), upper=Timestamp('2262-04-11 23:47:16.854775807'), inclusive='both')[source]#
Bases:
_DateTypeSeriesDetectorDetect if date value is between a given range.
Intended to be used by the detect method with the keyword ‘date_range’
>>> series.cleaner.detect.date_range(...) >>> series.cleaner.detect('date_range',...)
This detection method flags values as potential errors wherever the corresponding Series element is outside the date range.
Note
NA values are not treated as errors.
- Parameters:
lower (datetime) – Lower bound
upper (datetime) – Upper bound
inclusive ({“both”, “neither”, “left”, “right”}, default "both") – Include boundaries. Whether to set each bound as closed or open.
Examples
>>> series = pd.Series(['2022-10-01', '2021-06-11', '2019-04-03',' 2020-09-25']) >>> series= pd.to_datetime(series) >>> detector = series.cleaner.detect.date_range(lower='2020-06-15', upper='2022-08-05') >>> print(detector.is_error()) 0 True 1 False 2 True 3 False dtype: bool
With only one bound specified
>>> detector = series.cleaner.detect.date_range(upper='2022-08-05') >>> print(detector.is_error()) 0 True 1 False 2 False 3 False dtype: bool
Attributes Summary
Keyword to indicate if boundaries are included {“both”, “neither”, “left”, “right”}
Indices of the rows detected as errors
Lower bound
Number of rows detected as errors
The object (Series or DataFrame) containing the data to which the detection is applied
Upper bound
Methods Summary
detected()Series or DataFrame containing only the detected errors
Returns True if any error has been detected, False otherwise
is_date(date_str)Check if value is in date format
is_error()Return a boolean same-sized object indicating if the values are flagged as errors
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
- inclusive#
Keyword to indicate if boundaries are included {“both”, “neither”, “left”, “right”}
- index#
Indices of the rows detected as errors
- lower#
Lower bound
- n_errors#
Number of rows detected as errors
- name = 'date_range'#
- obj#
The object (Series or DataFrame) containing the data to which the detection is applied
- upper#
Upper bound
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