Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore_nan for distinctvalues #37

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pandas_schema/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,23 @@ class IsDistinctValidation(_SeriesValidation):
Checks that every element of this column is different from each other element
"""

def __init__(self, **kwargs):
def __init__(self, ignore_nan=False, **kwargs):
"""
:param ignore_nan: Whether or not to ignore nan values when checking for distinct values in a column.
"""

super().__init__(**kwargs)
self.ignore_nan = ignore_nan

@property
def default_message(self):
return 'contains values that are not unique'

def validate(self, series: pd.Series) -> pd.Series:
return ~series.duplicated(keep='first')
if self.ignore_nan:
return ~series.duplicated(keep='first') | series.isna()
else:
return ~series.duplicated(keep='first')


class InListValidation(_SeriesValidation):
Expand Down