Skip to content

Commit

Permalink
fix DataFrameSchema comparison with non-DataFrameSchema (#431)
Browse files Browse the repository at this point in the history
* increase cache version

* fix DataFrameSchema comparison with non-DataFrameSchema

* fix pylint error

Co-authored-by: cosmicBboy <[email protected]>
  • Loading branch information
Jean-Francois Zinque and cosmicBboy authored Mar 12, 2021
1 parent 40555d1 commit a2dca76
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
DEFAULT_PYTHON: 3.8
CI: "true"
# Increase this value to reset cache if environment.yml has not changed
CACHE_VERSION: 0
CACHE_VERSION: 1

jobs:
codestyle:
Expand Down
3 changes: 3 additions & 0 deletions pandera/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ def _format_multiline(json_str, arg):
)

def __eq__(self, other):
if not isinstance(other, type(self)):
return NotImplemented

def _compare_dict(obj):
return {
k: v for k, v in obj.__dict__.items() if k != "_IS_INFERRED"
Expand Down
10 changes: 10 additions & 0 deletions tests/core/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ def test_dataframe_schema():
schema.validate(df.assign(a=[1.7, 2.3, 3.1]))


def test_dataframe_schema_equality():
"""Test DataframeSchema equality."""
schema = DataFrameSchema({"a": Column(Int)})
assert schema == copy.copy(schema)
assert schema != "schema"
assert DataFrameSchema(coerce=True) != DataFrameSchema(coerce=False)
assert schema != schema.update_column("a", pandas_dtype=Float)
assert schema != schema.update_column("a", checks=Check.eq(1))


def test_dataframe_schema_strict():
"""
Checks if strict=True whether a schema error is raised because 'a' is
Expand Down

0 comments on commit a2dca76

Please sign in to comment.