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

Support for schemas smaller than the dataframe. #17

Closed
wants to merge 1 commit 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
6 changes: 4 additions & 2 deletions pandas_schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ def __init__(self, columns: typing.Iterable[Column], ordered: bool = False):
self.columns = list(columns)
self.ordered = ordered

def validate(self, df: pd.DataFrame, columns: typing.List[str] = None) -> typing.List[ValidationWarning]:
def validate(self, df: pd.DataFrame, columns: typing.List[str] = None, allow_sub_schema: bool = False) -> \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please split this over multiple lines so it doesn't need a linebreak escape

typing.List[ValidationWarning]:
"""
Runs a full validation of the target DataFrame using the internal columns list

:param df: A pandas DataFrame to validate
:param columns: A list of columns indicating a subset of the schema that we want to validate
:param allow_sub_schema: Allow to check sub schema
:return: A list of ValidationWarning objects that list the ways in which the DataFrame was invalid
"""
errors = []
Expand All @@ -44,7 +46,7 @@ def validate(self, df: pd.DataFrame, columns: typing.List[str] = None) -> typing
if columns is None:
schema_cols = len(self.columns)
columns_to_pair = self.columns
if df_cols != schema_cols:
if df_cols != schema_cols and not allow_sub_schema:
errors.append(
ValidationWarning(
'Invalid number of columns. The schema specifies {}, but the data frame has {}'.format(
Expand Down